zoukankan      html  css  js  c++  java
  • POJ 1845

    Sumdiv
    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 20029   Accepted: 5058

    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

    Hint

    2^3 = 8. 
    The natural divisors of 8 are: 1,2,4,8. Their sum is 15. 
    15 modulo 9901 is 15 (that should be output). 
     

    Source

      

     

    代码:

    #include<cstdio>
    #include<cstring>
    #ifdef unix
    #define LL "%lld"
    #else
    #define LL "%I64d"
    #endif
    #define mod 9901 
    using namespace std;
    typedef long long ll;
    const int N=1e5+10;
    ll tot,c[N/3],prime[N/3];
    bool check[N]={1,1};
    void get_prime(){
        ll n=10010;
        for(ll i=2;i<=n;i++){
            if(!check[i]) prime[++tot]=i;
            for(ll j=1;j<=tot&&i*prime[j]<=n;j++){
                check[i*prime[j]]=1;
                if(i%prime[j]==0) break;
            }
        }
    }
    ll mul(ll a,ll p,ll M){
        ll res=0;
        for(;p;p>>=1,a=(a+a)%M) if(p&1) res=(res+a)%M;
        return res;
    }
    ll fpow(ll a,ll p,ll M){
        ll res=1;
        for(;p;p>>=1,a=mul(a,a,M)) if(p&1) res=mul(res,a,M);
        return res;
    }
    void factor(ll A,ll B){
        ll ans=1;
        for(ll i=1;prime[i]*prime[i]<=A;i++){
            if(A%prime[i]==0){
                ll num=0;
                while(A%prime[i]==0) num++,A/=prime[i];
                ll MOD=(prime[i]-1)*mod;
                ans*=(fpow(prime[i],num*B+1,MOD)+MOD-1)/(prime[i]-1);
                ans%=mod;
            }
        }
        if(A>1){
            ll MOD=mod*(A-1);
            ans*=(fpow(A,B+1,MOD)+MOD-1)/(A-1);
            ans%=mod;
        }
        printf(LL"
    ",ans);
    }
    int main(){
        get_prime();
        for(ll A,B;scanf(LL LL,&A,&B)==2;) factor(A,B);
        return 0;
    } 
  • 相关阅读:
    sklearn KMeans聚类算法(总结)
    求素数的一个快速算法 Python 快速输出素数算法
    Java方法的多态
    Java static特性
    第一周-调用weka算法进行数据挖掘
    第一周 -神经网络算法与实现
    1【西北师大-2108Java】第一次作业成绩汇总
    第一周博客作业
    十一,专著研读(CART算法)
    十,专著研读(线性回归)
  • 原文地址:https://www.cnblogs.com/shenben/p/6264322.html
Copyright © 2011-2022 走看看