My code is showing correct answer for 1 test case and wrong answer on remaining cases. Please help
Showing wrong answer
Can you please explain the logic you used , your code is tough to comprehend.
First I found 10^6 prime numbers using prime seive because we have to multiply them by their powers in given array to find n. Then for finding power of different prime no. I use modular exponentiation as power can be large then I multiply them all like ((b[0]^prime[0])(b[1]^prime[1])…so on)=n. Now P=n^((No. of divisors of n)/2) and in my soln No.of divisors of n are po and P can be find by using modular exponentiation as it’s power can be large. Now after this I factorize P and find it’s prime factors with their powers and then for divisors of P, I multiply power of prime factor+1 for all prime factors and take their modulo and print that as answer.
Okay so the question has nothing to do with finding prime numbers, infact to find 10^6 prime numbers you would have to run sieve for a much bigger n.
See this code https://ide.codingblocks.com/s/257746
I am going to break down the code here.
This portion calculates the number of divisors of given number
long long nOfDivisors = 1;
for (long long i = 0; i<x; i++)
{
cin >> vec[i];
nOfDivisors = (nOfDivisors*(vec[i] + 1)) % p;
}
The product of all the divisors of a number N is N^(x/2) where x is the number of divisors of N. The number of divisors is given by product of prime powers+1 for N.
Now the next part is basic P&C.
for (long long i = 0; i<x; i++)
{
vec[i] = (nOfDivisors*vec[i])%p;
vec[i] = (vec[i]*500000004)%p; // 500000004 is mod_inv(2,1000000007);
ans = (ans*(vec[i] + 1)) % p;
}
Thanks for your explanation, I got it.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.