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

 

转载于:https://www.cnblogs.com/Just--Do--It/p/6561812.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值