c++ - function that calculates sum of proper divisors -
i encountered problem on spoj requires user calculate sum of divisors of number (n) modulus number (m)
http://www.spoj.com/problems/hdevil/
while calculating if use function, spoj gives wa. unable find problem function. advice welcome , appreciated.
int i=0; ll prod=1; while(seive[i]*seive[i]<=n) { int p=seive[i],j=1; ll count=1; while(n%p==0) { count+=modpow(p,j,mod); j++; n/=p; } prod=((prod%mod)*(count%mod))%mod; i++; } if(n>1) { prod*=n+1; prod%=mod; } here prod final sum , seive[] stores prime numbers , modpow power modulus function.
find factors of n, use divisor summatory function compute sum of divisors of n, taking products modulo m. in problem n < 109, simple factoring function based on trial division sufficient.
ask questions if need additional help.
Comments
Post a Comment