Poj 1845 sumdiv (number theory, evaluate all the divisor sums of a ^ B)

Source: Internet
Author: User
Sumdiv
Time limit:1000 ms   Memory limit:30000 K
Total submissions:10071   Accepted:2357

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 in 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.
15 modulo 9901 is 15 (that shoshould be output ).

Source

Romania oi 2002 question: Calculate the result after modulo 9901 for the sum of all the approx. s of a ^ B.
According to the unique decomposition theorem, A can be obtained by means of Factorization: A = p1 ^ A1 * P2 ^ A2 * P3 ^ A3 * PN ^.
A ^ B = p1 ^ (A1 * B) * P2 ^ (A2 * B) *... * PN ^ (an * B );
Sum = [1 + p1 + p1 ^ 2 +... + p1 ^ (A1 * B)] * [1 + p2 + p2 ^ 2 +... + p2 ^ (A2 * B)] * [1 + Pn + PN ^ 2 +... + PN ^ (an * B)]. proportional Series 1 + PI ^ 2 + PI ^ 3 +... + PI ^ N can be obtained by binary (that is, the formula to be solved is divided into parts to solve)
If n is an odd number and a total number of even items exist and P is set to 3, (1 + p) + (P ^ 2 + P ^ 3) = (1 + p) + P ^ 2 (1 + p) = (1 + P ^ 2) * (1 + p) 1 + P ^ 2 + P ^ 3 + ........ + P ^ n = (1 + P ^ 2 + .... + P ^ (n/2) * (1 + P ^ (n/2 + 1 ));
If n is an even number, there are a total of odd values. If P is set to 4, (1 + p) + P ^ 2 + (P ^ 3 + P ^ 4) = (1 + p) + P ^ 2 + P ^ 3 (1 + p) = (1 + P ^ 3) * (1 + p) + P ^ 2 1 + P ^ 2 + P ^ 3 + ........ + P ^ n = (1 + P ^ 2 + .... + P ^ (n/2-1) * (1 + P ^ (n/2 + 1 ));
 /*  Poj 1845 sumdiv calculates the sum of all the approx. % 9901 of a ^ B  */  # Include <Stdio. h> # Include <Math. h># Include <Iostream> # Include <Algorithm> # Include < String . H> Using   Namespace  STD;  # Define Mod4 9901 //  **************************************** **  //  Prime Number filtering and number Decomposition  Const   Int Maxn =10000  ;  Int Prime [maxn + 1  ];  Void  Getprime () {memset (prime,  0 , Sizeof  (PRIME ));  For ( Int I = 2 ; I <= maxn; I ++ ){  If (! Prime [I]) prime [++ prime [0 ] = I;  For ( Int J = 1 ; J <= prime [ 0 ] & Prime [J] <= maxn/I; j ++ ) {Prime [prime [J] * I] = 1  ;  If (I % prime [J] = 0 ) Break  ;}}} Long   Long Factor [ 100 ] [ 2  ];  Int  Fatcnt;  Int Getfactors ( Long   Long  X) {fatcnt = 0  ;  Long   Long TMP = X; For ( Int I = 1 ; Prime [I] <= tmp/prime [I]; I ++ ) {Factor [fatcnt] [  1 ] = 0  ;  If (TMP % prime [I] = 0  ) {Factor [fatcnt] [  0 ] = Prime [I];  While (TMP % prime [I] =0  ) {Factor [fatcnt] [  1 ] ++ ; TMP /= Prime [I];} fatcnt ++ ;}}  If (TMP! = 1  ) {Factor [fatcnt] [  0 ] = TMP; factor [fatcnt ++] [ 1 ] = 1 ;}  Return  Fatcnt ;}  //  **************************************** **  Long   Long Pow_m ( Long   Long A, Long   Long N) //  Fast modulo operation  {  Long   Long Res = 1  ;  Long   Long TMP = A % MOD;  While  (N ){  If (N & 1 ) {Res * = TMP; Res % = MOD;} n >>= 1  ; TMP * = TMP; TMP % = MOD ;} Return  Res ;}  Long   Long Sum ( Long   Long P, Long   Long N) //  Calculate 1 + P ^ 2 + ''' + P ^ n  {  If (P = 0 ) Return   0  ; If (N = 0 ) Return   1  ;  If (N & 1 ) //  Odd  {  Return (( 1 + Pow_m (p, N/ 2 + 1 ) % Mod * sum (p, N/ 2 ) % Mod) %MOD ;}  Else   Return (( 1 + Pow_m (p, N/ 2 + 1 ) % Mod * sum (p, N/ 2 - 1 ) + Pow_m (p, N/ 2 ) % Mod) % MOD ;}  Int  Main (){  //  Freopen ("in.txt", "r", stdin ); //  Freopen ("out.txt", "W", stdout );      Int  A, B; getprime ();  While (Scanf ( "  % D  " , & A, & B )! = EOF) {getfactors ();  Long   Long Ans = 1  ;  For ( Int I = 0 ; I <fatcnt; I ++ ) {Ans * = (Sum (factor [I] [ 0 ], B * factor [I] [ 1 ]) % MoD); ans % = MOD;} printf (  "  % I64d \ n  "  , ANS );}  Return   0  ;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.