Problem Description
Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).
Input
The only line contains the two natural numbers A and B, (0 <= A,B <= 50000000)separated by blanks.
Output
The only line of the output will contain S modulo 9901.
Sample Input
2 3
Sample Output
15
***************************************************************************************************************************
S = (1+p1+p1^2+p1^3+...p1^k1) * (1+p2+p2^2+p2^3+….p2^k2) * (1+p3+ p3^3+…+ p3^k3) * .... * (1+pn+pn^2+pn^3+...pn^kn);S表示约数的个数,这个式子很好推,稍微想一想就明白啦,(注意p是质数,这就是一个因数和的分解因式,可以还原试一试)(说明数学很重要啊!!)
***************************************************************************************************************************
1 #include<iostream> 2 #include<cstdio> 3 #include<math.h> 4 5 #define SIZE_N 10000 6 #define MODE 9901 7 using namespace std; 8 typedef __int64 llg; 9 10 int prime[SIZE_N],cnt[SIZE_N]; 11 12 13 int My_power(llg n,int m)//求一个q^n的幂值 14 { 15 llg ans = 1; 16 while(m) { 17 if(m & 1) { 18 ans = (ans * n) % MODE; 19 } 20 n = (n * n) % MODE; 21 m >>= 1; 22 } 23 return ((ans == 0) ? MODE : ans); 24 } 25 26 llg Sum_gp(llg p, llg n)//求和的幂值 27 { 28 if(n == 0) return 1; 29 if(n & 1) 30 return ((1+My_power(p, n/2+1)) * Sum_gp(p, n/2)) % MODE; 31 else 32 return ((1+My_power(p, n/2+1)) * Sum_gp(p, n/2-1) + My_power(p, n/2)) % MODE; 33 } 34 35 36 37 int Sumdiv(int a,int b) 38 { 39 int i,j,xz; 40 int ans = 1; 41 42 xz = sqrt(a); 43 for(i = 2,j = 0;i < xz;i ++) { 44 if(a % i == 0) { 45 prime[j] = i; 46 while(a % i == 0) { 47 cnt[j] ++; 48 a /= i; 49 } 50 j ++; 51 } 52 } 53 if(a != 1) { 54 prime[j] = a; 55 cnt[j++] = 1; 56 } 57 for(i = 0;i < j;i ++) { 58 ans = (ans * Sum_gp(prime[i],cnt[i]*b)) % MODE; 59 } 60 return ans; 61 } 62 63 int main() 64 { 65 int a,b; 66 int ans; 67 68 while(scanf("%d%d",&a,&b) != EOF) { 69 ans = Sumdiv(a,b); 70 printf("%d ",ans); 71 } 72 return 0; 73 }