【数论】【poj1845】Sumdiv
2017-10-11 15:36
316 查看
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 3Sample Output
15Hint
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; }
相关文章推荐
- poj 1845 Sumdiv 数论--等比数列和(逆元或者递归)
- poj 1845 Sumdiv(数论+二分)
- POJ 1845 Sumdiv (数论,约数和)
- 【数论】POJ_1845_Sumdiv
- poj 1845 Sumdiv(数论:欧拉函数+二分求等比数列前n项和+快速幂取模)
- poj 1845 Sumdiv <数论>
- poj 1845 Sumdiv (很多数论知识 ,很经典 )
- POJ 1845-Sumdiv 数论 +快速幂&&筛素&&分解质因数&&求因数之和的模板
- Sumdiv POJ - 1845 (数论)
- poj-1845-Sumdiv-数论-快速幂取模+快速分解因式
- [poj1845] Sumdiv(数论,质因数分解,约数和,快速幂)
- POJ-1845 Sumdiv 数论
- poj1845——Sumdiv(数论+幂的因子和)
- poj1845--Sumdiv(数论篇3--真滴是数论啊。。。。)
- poj 1845 Sumdiv 数论
- POJ 1845 sumdiv 数论 A^B 的所有约数之和
- poj1845 Sumdiv(数论,因数和,等比数列,快速幂)
- poj 1845 Sumdiv (数论)
- [POJ1845]Sumdiv(数论+矩乘)
- [数论+二分求等比数列]POJ 1845 Sumdiv