隐藏页面特效

POJ 1845

Sumdiv
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 20029   Accepted: 5058

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). 
 

Source

  

 

代码:

#include<cstdio> #include<cstring> #ifdef unix #define LL "%lld" #else #define LL "%I64d" #endif #define mod 9901 using namespace std; typedef long long ll; const int N=1e5+10; ll tot,c[N/3],prime[N/3]; bool check[N]={1,1}; void get_prime(){ ll n=10010; for(ll i=2;i<=n;i++){ if(!check[i]) prime[++tot]=i; for(ll j=1;j<=tot&&i*prime[j]<=n;j++){ check[i*prime[j]]=1; if(i%prime[j]==0) break; } } } ll mul(ll a,ll p,ll M){ ll res=0; for(;p;p>>=1,a=(a+a)%M) if(p&1) res=(res+a)%M; return res; } ll fpow(ll a,ll p,ll M){ ll res=1; for(;p;p>>=1,a=mul(a,a,M)) if(p&1) res=mul(res,a,M); return res; } void factor(ll A,ll B){ ll ans=1; for(ll i=1;prime[i]*prime[i]<=A;i++){ if(A%prime[i]==0){ ll num=0; while(A%prime[i]==0) num++,A/=prime[i]; ll MOD=(prime[i]-1)*mod; ans*=(fpow(prime[i],num*B+1,MOD)+MOD-1)/(prime[i]-1); ans%=mod; } } if(A>1){ ll MOD=mod*(A-1); ans*=(fpow(A,B+1,MOD)+MOD-1)/(A-1); ans%=mod; } printf(LL"\n",ans); } int main(){ get_prime(); for(ll A,B;scanf(LL LL,&A,&B)==2;) factor(A,B); return 0; }

 


__EOF__

本文作者shenben
本文链接https://www.cnblogs.com/shenben/p/6264322.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   神犇(shenben)  阅读(1008)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示