Author: Vamsi Kavala PROBLEM LINKSDIFFICULTYCakewalk PREREQUISITESSimple Math, Integer Factorization Problem:You are given a very large number represented as a product of N numbers. Given this number representation, you need to find the number of distinct factors of the original number which is formed by the product of given N numbers. Quick Explanation:We can factorize each one of the N given numbers into its prime factors. Then we find the number of occurrences of each prime factor, say they are a1, a2,...aK, if we have K distinct prime factors. Our answer is simply: (a1+1)(a2+1)(...)*(aK+1). Detailed Explanation:This problem relies on some knowledge of divisor function. Divisor functions returns the number of positive and distinct divisors of a number. Let's call it d(x).
This allows us to deduce the important relationship, that is the key of solving this problem: For a prime number, p, we have: d(p^n) = n+1. Now, it's easy to understand that all we need to do is to factorize all the N given numbers into its prime factors, and, for each prime factor we also need to count how many times it appears (that is, we need to know the exponent of each prime factor). Once we have this count with us (which can be done using integer factorization and for example, the set and map data structures, one to guarantee uniqueness of the factors and the other to save the number of occurences for each unique prime factor), all we need to do is to multiply all these numbers plus one together and we will obtain our answer. As an example, consider the number: 504 = 2^3 * 3^2 * 7^1 The number of distinct divisors of 504 is then (3+1) * (2+1) * (1+1) = 24. Applying this process to all numbers yields the answer to the problem :) SETTER'S SOLUTIONCan be found here. TESTER'S SOLUTIONTester's solution will be uploaded soon. Useful LinksWhat is a multiplicative function?
This question is marked "community wiki".
asked 30 Jun '13, 14:10

@shasha1s2 wen u update 'other' array to count prime u do not account for the fact that the prime number being counted may be the same..in other words, the value of other[i] (according to your code) will never be more than 1...going by that the test case 5 999983 999983 999983 999983 999983 will give 32 as per your code, while ans is 6. answered 30 Jun '13, 16:40
thanx @amitrc17 got my error...
(30 Jun '13, 19:23)

@roshi...it will most certainly give a TLE as the time complexity is very high!!!! try using Sieve of Eratosthenes....see the time difference....Naive approach....seive!!! answered 30 Jun '13, 23:08
A simple modification of Sieve of Erastothenes will also prove to be helpful. The following is what I used. f[i] == 0 if i is prime, and if i is prime, then f[i] will have the smallest prime that will divide it. for (int i = 2; i <= N; i++) if (!f[i]) for (int j = i+i; j <= N; j += i) if (!f[j]) f[j] = i; f[i] will help a lot to find all the prime divisors of a number.
(01 Nov '13, 15:03)
http://www.codechef.com/viewsolution/2894661 A shorter solution with the same concept + the subtle modification of the sieve to store prime factor info.
(01 Nov '13, 15:06)

@shubham26 if you look at the constraints .They are : N<=10 Ai<=1000000 and as in your code you multiply each Ai to get a number which is product of all of them. Suppose if all the numbers are 10^6 and N=10 and they are multiplied N times,the number becomes (10^6)^10=10^60 which is far beyond the range of long(range of the order 10^9)( (even its far away from long long(range of the order 10^18)). answered 01 Jul '13, 08:45
@dhruvagga : thanks..I got it. :)
(01 Jul '13, 14:55)

In the setter's solution what is the use of this code fragment if(a[i]!=1) { if(m.find(a[i])!=m.end()) m[a[i]]++; else m.insert(MP(a[i],1)); from line 85 to 90 I put that in comments and ran the program and it gave the correct o/p for test cases. I don't understand it's use. After dividing with all the prime numbers shouldn't a[i] necessarily be 1. answered 12 Jul '13, 23:30

Can you tell me where my code fails... I have applied same concept i think.. http://www.codechef.com/viewsolution/2304397 answered 30 Jun '13, 14:15

Either you can use a sieve to extend your primes array or just put more primes in the primes array. here's a sample code for sieve. http://ideone.com/arhRSv answered 30 Jun '13, 15:49

It gives a TLE when i use the function 'prime' to find the prime factorisation of the number.Can someone please tell me where i went wrong? Thanks in advance. Here is the link to my code : http://ideone.com/kgzICq answered 30 Jun '13, 22:52

What is wrong in my code?? http://ideone.com/Y5mZLP It gives correct answers to all the numbers with which I have checked. :( answered 01 Jul '13, 02:09

Can anyone provide critical input. My solutions keeps getting WA, however, when comparing to AC code gives same output.
answered 28 Oct '13, 00:25

whats the problem wid following ? i got a WA
answered 27 Jun '14, 18:31

my code is running fine on the first time.. but in second test case giving erronous output.. please help..
answered 29 Jun '14, 22:36

Hey whats wrong in my code here?
I am getting runtime error NZEC. answered 24 Jun '15, 08:47

I have been trying to debug my code for so long still not able to figure out why it is giving a WA for the basic cases. Please if anyone could tell me where am I going wrong?
This is the link to my solution. answered 30 Oct '15, 19:30

nice explanation. I used sieve of eratosthenes to get all prime factors of number answered 19 Nov '15, 22:33

https://www.codechef.com/viewsolution/14084014 WHY IS THIS SOLUTION GETTING A WA ON LAST CASE PLZ HELP!! answered 05 Jun '17, 18:53

why time limit exist????answered 04 Oct '13, 17:20

In your code, you are checking whether a[i] == 1 towards the end. But can you give me a case where it wont be equal to 1. Wont the prime numbers stored in the list make sure that the smallest number is being factorized first and then proceed to the largest??
Any special reason for using char type of array for storing primes by setter ?