And factors (Luo Valley P1593) - divisors and prime factor decomposition +

topic:

Find all divisors A ^ B and (A, B <= 5e7)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 40
#define mod 9901
ll num[N],p[N];
int cnt=0;
ll quick_pow(ll a,ll k)
{
    ll ans=1;
    while(k){
        if(k&1) ans=ans*a %mod;
        a=a*a %mod;
        k>>=1;
    }
    return ans;
}
void devide(ll a)
{
    for(int i=2;i*i<=a;i++)//根号n地分解质因数 
    if(a%i==0){
        p[++cnt]=i;
        while(a%i==0) a/=i,num[cnt]++;
    }
    if(a>1) p[++cnt]=a,num[cnt]++;//防止a是质数 
}
int main()
{
    ll a,b,ans=1;
    scanf("%lld%lld",&a,&b);
    devide(a);//printf("cnt:%d\n",cnt);
    for(int i=. 1 ; I <= CNT; I ++ ) {
         IF ((p [i] - . 1 )% MOD == 0 ) ANS ANS = * (NUM [I] + . 1 ) MOD%; // additional discussion p [i] - 1 mod divisible case when it does not, this inverse element
         // P [I] -1 (=) is mod p [i] (=) 1 (% mod) is transformed into the original formula b * num [i] +1 adding a 1 
        the else { 
            LL X = quick_pow (P [I], NUM [I] * B + 1 ), quick_pow INV = (P [I] - 1 , mod- 2 ); 
            ANS = ANS * (X- 1 ) INV *% MOD% MOD; 
        } 
    } 
    the printf ( " % LLD \ n- " , ANS); 
} 
/ *
10000000 10000000
*/

 

Guess you like

Origin www.cnblogs.com/mowanying/p/11426267.html