11960 - Divisor Game
Solution Description : Math prime number, prime factor, divisor problem You need to find number of divisor of a number using this method: If we know the prime factorization of a number, we can easily find the number of divisors. For example, 18 has 6 divisors. If we prime factorize 18, we find that 18 = 21 * 32 We can say that any divisor of 36 should be in the form 2x * 3y So, we can say that the number of divisors of 18 is (1 + 1) * (2 + 1) = 6 So, if a number is factorized as 2x * 3y Then the number of divisors is (x+1) * (y+1). Similarly, suppose a number is factorized as 2x * 3y * 5z, so, the total number of divisors is (x + 1) * (y + 1) * (z + 1) Now, the general formula is If the prime factorization of an integer is p1x1 * p2x2 * p3x3 * ... * pnxn where, p1, p2, ..., pn are primes, then the number of divisors is (x1 + 1) * (x2 + 1) * (x3 + 1) * ... * (xn + 1) set ans[1]=1 max=max_num_div=1; for i=2 to 1000000 ---- set n = number of divisor of i // find it using method which is describe in above. ---- if n>=max_num_div then set max_num_div=n and max=i ---- set ans[i]= max For each input n print ans[n] |
||||||||||