• 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
  • 相关阅读:
    关于连接connection reset的问题
    Redis应用场景及缓存问题
    zookeeper集群及kafka集群搭建
    使用自定义注解和切面AOP实现Java程序增强
    Shell脚本控制docker容器启动顺序
    正则表达式匹配${key}并在Java中使用
    Redis基本数据结构之ZSet
    Redis基本数据结构之Set
    Redis基本数据结构之Hash
    Redis基本数据结构之List
  • 原文地址:https://www.cnblogs.com/buerdepepeqi/p/9141267.html
Copyright © 2020-2023  润新知