Sumdiv Geometric Series summation

Source: Internet
Author: User

Sumdiv

Sumdiv
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 15364 Accepted: 3790

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

Romania OI 2002

Approximate test instructions:

The sum of all the approximations (i.e. factors) of the a^b is obtained, and the modulo 9901 is then output.

Problem Solving Ideas:

A problem that requires strong mathematical thinking

There are three application theorems:

A problem that requires strong mathematical thinking

There are three application theorems:

(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

With the above mathematical basis, the method is simple:

1: Decomposition of a by element factor

Method of decomposing A:

A first to the first prime number 2 constantly take the mold, a%2==0, record 2 occurrences of the frequency +1,a/=2;

When A%2!=0, a to the next continuous prime number 3 constantly take the mold ...

And so on until A==1.

Pay attention to the special judgment, when a itself is a prime, can not be decomposed, it itself is its own prime decomposition formula.

Finally get a = P1^K1 * p2^k2 * p3^k3 *...* pn^kn.
So a^b = p1^ (k1*b) * p2^ (k2*b) *...* pn^ (kn*b);


The sum of all the 2:a^b is:

sum = [1+p1+p1^2+...+p1^ (a1*b)] * [1+p2+p2^2+...+p2^ (A2*B)] *...* [1+pn+pn^2+...+pn^ (An*b)].


3: Using recursive two-part to seek geometric series 1+pi+pi^2+pi^3+...+pi^n:

(1) If n is an odd number, there are even items, then:
1 + p + p^2 + p^3 +...+ p^n

= (1+p^ (n/2+1)) + p * (1+p^ (n/2+1)) +...+ p^ (N/2) * (1+p^ (n/2+1))
= (1 + p + p^2 +...+ p^ (N/2)) * (1 + p^ (n/2+1))

The first half of the upper red Bold is just half the original, so you just need to keep the recursive two sums on it, the second half is power, and the calculation method will be described in the 4th below.

(2) If n is an even number, there are odd numbers, then:
1 + p + p^2 + p^3 +...+ p^n

= (1+p^ (n/2+1)) + p * (1+p^ (n/2+1)) +...+ p^ (n/2-1) * (1+p^ (n/2+1)) + p^ (N/2)
= (1 + p + p^2 +...+ p^ (n/2-1)) * (1+p^ (n/2+1)) + p^ (N/2);

The first half of the upper red Bold is exactly half the original, and still the recursive solution

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <string>7#include <vector>8#include <stack>9#include <queue>Ten#include <Set> One#include <map> A#include <list> -#include <iomanip> -#include <cstdlib> the#include <sstream> - using namespacestd; -typedefLong LongLL; - Const intinf=0x4fffffff; + Const Doubleexp=1e-6; - Const intms=1000005; + ConstLL mod=9901; A  at ll Pow_mod (ll x,ll N) - { -LL res=1; -        while(n) -       { -             if(n&(1LL)) in                   //Res=res*x%mod; -Res= ((res%mod) * (x%mod))%MoD; ton>>=1; +            //X=x*x%mod; -x= (X%MOD) * (xMoD); the       } *       returnRes; $ }Panax Notoginseng  -LL Calc (ll X,ll y)//Sigma (0->y) x^i the { +       if(y==0) A             return 1; the       if(y&(1LL)) +             return(Calc (x,y/2)%mod) * ((Pow_mod (x,y/2+1)+1) (%mod))%MoD; -             //return Calc (X,Y/2) * (1+pow_mod (x,y/2+1)); $       Else $             return((Calc (x,y/2-1)%mod) * ((Pow_mod (x,y/2+1)+1) (%mod))%mod+pow_mod (x,y/2)  )%MoD; -            //return Calc (x,y/2-1) * (Pow_mod (x,y/2+1) +1) +pow_mod (X,Y/2); - } the  - LL Prime[ms];Wuyi LL Cnt[ms]; the  - intMain () Wu { - LL x, y; AboutCin>>x>>y; $ll t= (LL) (sqrt (x*1.0)+EXP); -LL k=0; -        for(LL i=2; i<=t;i++) -       { A             if(x%i==0) +             { theprime[k]=i; -                    while(x%i==0) $                   { thecnt[k]++; theX/=i; the                   } thek++; -             } in       } the       if(x!=1LL) the       { Aboutprime[k]=x; thecnt[k++]=1; the       } the  +LL ans=1LL; -        for(LL i=0; i<k;i++) theAns= (Ans%mod*calc (prime[i],cnt[i]*y)%mod)%MoD;Bayicout<<ans<<Endl; the       return 0; the}

Sumdiv Geometric Series summation

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.