please explain the maths behind it
I can get no of divisors by formula
no of divisors*(A[i]+1*)
for 1<=i<=n.
I saw a solution on hacker earth .
i got the maths behind it partially can you expain the part from “product of all the divisors of N” part.
Playing with divisors is fun
The product of all the divisors of a number N is N^x where x is the number of divisors of N.
The number of divisors is given by product of prime powers+1 for N. for example if N = 12 than its number of divisors are (2+1)*(1+1) = 6. you are already given the prime powers of N hence its number of divisors can be calculated.
so after finding P should i break it into prime factors and then agan use the same formula for finding no. of divisors??
can you explain the above editorial of hackerearth? it’s same question i think/
Its difficult to explain it here.
All it says is this:
int prod=1;
for(int i=0;i<n;i++)
{
prod=(prod*(ar[i]+1))%MOD;
}
int ans=1;
for(int i=0;i<n;i++)
{
ans=(ans*((ar[i])*(prod/2)+1))%MOD;
}
cout<<ans;
I hope you can understand the logic now .
If you first make the complete product and then break it again, you might get TLE.
Direct step shall be used.
Its just this much code of work.
1.Calculating prod…you knw
2. Explanation is given in that tutorial, carefully go through it. I know its difficult to understand.
You can have a look at this complete code here or any other accepted code from hackerearth only.