zoukankan      html  css  js  c++  java
  • poj 1845: Sumdiv

    题目链接

    先将A^B分解质因数,可以通过先分解A,再把对应的幂次*B。之后用下面这个式子求解就可以了

    #include<vector>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    
    const int mod=9901;
    const int N=1e4+5;
    
    LL A,B;
    bool not_prime[N+5];
    vector<int> prime;
    
    void init()
    {
        for(int i=2;i<N;i++)
        {
            if(!not_prime[i])
            {
                prime.push_back(i);
                for(int j=i*i;j<N;j+=i)
                    not_prime[j]=true;
            }
        }
    }
    
    LL qpow(LL x,LL n)
    {
        LL ret=1;
        for(;n;n>>=1)
        {
            if(n&1) ret=ret*x%mod;
            x=x*x%mod;
        }
        return ret;
    }
    
    LL sum(LL q,LL n)    //求首项为1,公比为q 的等比数列的前n项和 
    {
        if(n==1) return 1;
        LL ret=0;
        LL ls=sum(q,n/2);
        LL rs=ls*qpow(q,n/2)%mod;
        ret=(ls+rs)%mod;
        if(n&1) ret=(ret+qpow(q,n-1))%mod;
        return ret;
    }
    
    LL cal(LL A,LL B)
    {
        LL ret=1;
        for(int i=0;prime[i]*prime[i]<=A&&i<prime.size();i++)
        {
            if(A%prime[i]==0)
            {
                int cnt=0;
                while(A%prime[i]==0) cnt++,A/=prime[i];
                ret=ret*sum(prime[i],cnt*B+1)%mod;
            }
        }
        if(A>1) ret=ret*sum(A,B+1)%mod;
        return ret;
    }
    
    int main()
    {
        init();
        while(cin>>A>>B)
            cout<<cal(A,B)<<endl;
    }
    View Code
  • 相关阅读:
    C语言运算符优先级和口诀
    跨域问题的解决方案 php
    浅谈跨域攻击及预防
    浅析Websocket--PHP
    linux下的删除目录和文件的方法
    python魔法方法
    双指针
    python常用模块
    python三大器
    对闭包的误区
  • 原文地址:https://www.cnblogs.com/Just--Do--It/p/6561812.html
Copyright © 2011-2022 走看看