Sumdiv
Time Limit: 1000MS |
|
Memory Limit: 30000K |
Total Submissions: 15745 |
|
Accepted: 3894 |
Description
Consider natural numbers A and B. Let S is 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 natural numbers A and B, (0 <= A, b <= 50000000) separated by blanks.
Output
The only line of the output would contain S modulo 9901.
Sample Input
2 3
Sample Output
15
Hint
2^3 = 8.
The natural divisors of 8 are:1,2,4,8. Their sum is 15.
Modulo 9901 is (that's should be output).
Source
recently in the study of some knowledge of number theory, feel no place to start, had to follow the corresponding topic to learn, do this problem need to use the following knowledge points.
(1) The unique decomposition theorem for integers:
Any positive integer has and only one way to write the product expression of its element factor.
A= (P1^K1) * (P2^K2) * (P3^K3) *....* (PN^KN) where pi is prime
(2) Approximate and formula:
For an already decomposed integer a= (p1^k1) * (P2^K2) * (P3^K3) *....* (PN^KN)
There is a sum of all the factors of a
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)
(3) The same comodule formula:
(a+b)%m= (a%m+b%m)%m
(a*b)%m= (a%m*b%m)%m
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < stdlib.h>using namespace Std;const int h = 10001;int n,m;struct node{int x; int y;} Q[h];long long int power (long long int pn,long long int pm)//////repeated flat method to seek a^b time {long long int sq = 1; while (pm>0) {if (pm%2) {sq = (SQ*PN)%9901; } pm = PM/2; PN = PN * PN% 9901; } return sq;} Long Long int updata (long long int pn,long long int pm)////recursive binary for geometric series and {if (pm = = 0) {return 1; } if (pm%2) {return (Updata (PN,PM/2) * (1+power (pn,pm/2+1)))%9901; When PM is odd, there are formulas for geometric series and (1 + p + p^2 +...+ p^ (N/2)) * (1 + p^ (n/2+1))} else {return (Updata (pn,pm/2-1) * (1+power (pn,pm/2+1)) + power (PN,PM/2))%9901; When the PM is even, there is a formula for geometric series (1 + p + p^2 +...+ p^ (n/2-1)) * (1+p^ (n/2+1)) + p^ (N/2); }}int Main () {while (scanf ("%d%d", &n,&m)!=eof) {int k = 0; for (iNT i=2;i*i<=n;)///search for a quality factor, a good method {if (n%i = = 0) {q[k].x = i; Q[K].Y = 0; while (n%i = = 0) {q[k].y++; n/= i; } k++; } if (i = = 2) {i++; } else {i = i + 2; }} if (n!=1) {q[k].x = n; Q[K].Y = 1; k++; } int ans = 1; for (int i=0;i<k;i++) {ans = (ans* (updata (q[i].x,q[i].y*m)%9901)%9901); } printf ("%d\n", ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 1845 Sumdiv (number theory)