【数论】【poj1845】Sumdiv

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,求A^B的所有因数的和,再MOD 9901

思路

这题我们首先看,求的是A^B的因子之和
我们首先分解A
因为任何一个数都可以分解为素数的幂次方相乘:
所以:A=(p1^k1)*(p2^k2)………;
其中p是素数,k是这个数最多能被除几次(幂的次数);
因子个数就是:
(1+2+……..k1)(1+2+……….k2) ……个
那么因子之和就是
(1+p1^1+…..p1^k1)(1+p2^2+…..p2^k2) ………..;
a^b=(p1^k1* b) * (p2^k2*b)…..;
1+p1^1+…..p1^k1这就是一个等比数列
我们分奇和偶讨论 提出他们的通项以减少次方数求解;

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#define ll long long
#define mo 9901
using namespace std;
inline int read(){
    int ret=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())ret=ret*10+c-'0';
    return ret*f;
}
inline ll ksm(ll x,ll y){
    ll ans=1ll;
    x%=mo;
    while(y){
        if(y&1)(ans*=x)%=mo;
        (x*=x)%=mo;
        y>>=1;
    }
    return ans%mo;
}
ll sum(ll x,ll y){
    if(!y)return 1;
    else if(y&1)return (sum(x,y/2)*(1+ksm(x,y/2+1))%mo);
    else return ((sum(x,y/2-1)*(1+ksm(x,y/2+1)))%mo+ksm(x,y/2)%mo)%mo;
}
ll n,m,a;
int main(){
    while(scanf("%lld%lld",&a,&m)==2){
        if(m==0||a<=1){printf("1\n");continue;}
        ll ans=1;
        ll n=sqrt(a+0.5);
        for(int i=2;i<=n;++i){
            if(!(a%i)){
                ll cnt=0ll;
                while(!(a%i)){
                    ++cnt;
                    a/=i;
                }
                (ans*=sum(i,cnt*m))%=mo;
            }
        }
        if(a>1)(ans*=sum(a,m))%=mo;
        printf("%lld\n",ans);
    }
    return 0;
}   
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值