• POJ


    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). 
    题意:求 a^b 的所有约数的和
    题解:
    tips:
    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    
    using namespace std;
    const int mod=9901;
    const int maxn=5e5+5;
    typedef long long ll;
    ll p[maxn];
    int prime[maxn];
    void is_prime() {
        int cnt=0,i,j;
        memset(prime,0,sizeof(prime));
        for(i=2; i<maxn; i++) {
            if(prime[i]==0) {
                p[++cnt]=i;
                for(j=2*i; j<maxn; j=j+i) {
                    prime[j]=1;
                }
            }
        }
    }
    ll multi(ll A,ll n,ll k) {
        ll b=0;
        while(n>0) {
            if(n&1) {
                b=(b+A)%k;
            }
            n=n>>1;
            A=(A+A)%k;
        }
        return b;
    }
    ll getresult(ll A,ll n,ll k) {
        ll b=1;
        while(n>0) {
            if(n&1) {
                b=multi(b,A,k);
            }
            n=n>>1;
            A=multi(A,A,k);
        }
        return b;
    }
    void solve(ll A,ll B) {
        int i;
        ll ans=1;
        for(i=1; p[i]*p[i]<=A; i++) {
            if(A%p[i]==0) {
                int num=0;
                while(A%p[i]==0) {
                    num++;
                    A=A/p[i];
                }
                ll m=(p[i]-1)*9901;
                ans*=(getresult(p[i],num*B+1,m)+m-1)/(p[i]-1);
                ans%=9901;
            }
        }
        if(A>1) {
            ll m=9901*(A-1);
            ans *= (getresult(A,B+1,m)+m-1)/(A-1);
            ans%=9901;
        }
        cout<<ans<<endl;
    }
    int main() {
        ll A,B;
        is_prime();
        while(cin>>A>>B) {
            solve(A,B);
        }
        return 0;
    }
    View Code
    每一个不曾刷题的日子 都是对生命的辜负 从弱小到强大,需要一段时间的沉淀,就是现在了 ~buerdepepeqi
  • 相关阅读:
    thinkphp5整合 gatewaywork实现聊天
    php输出日志
    php的ob函数实现页面静态化
    30个php操作redis常用方法代码例子
    redis三种启动方式
    Redis实战
    支付宝即时到账接口开发
    PHP生成excel表格文件并下载
    微信平台提供三种公众号
    【Performance】chrome调试面板
  • 原文地址:https://www.cnblogs.com/buerdepepeqi/p/9141267.html
Copyright © 2020-2023  润新知