标签:return 9901 int MO Sumdiv 1845 POJ include sum
http://poj.org/problem?id=1845
题目
Time Limit: 1000MS | Memory Limit: 30000K |
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).
题解
筛素数后试除不行,因为空间限制
直接试除
得到了$1\sim \sqrt{A}$的素因子,可以肯定剩下的那个一定是素数,就像之前的Safe Upperbound一样
占坑= =
AC代码
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #include<set> #include<cassert> #define REP(r,x,y) for(register int r=(x); r<(y); r++) #define REPE(r,x,y) for(register int r=(x); r<=(y); r++) #ifdef sahdsg #define DBG(...) printf(__VA_ARGS__) #else #define DBG(...) (void)0 #endif using namespace std; typedef long long LL; typedef pair<LL, LL> pll; typedef pair<int, int> pii; #define MO 9901 #define MAXN 50000007 inline int qpow(int a, int b) { a%=MO; int ans=1; for(;b;b>>=1) { if(b&1) ans=(LL)ans*a%MO; a=(LL)a*a%MO; } return ans; } int sum(int a, int b) { if(a==0) return 0; if(b==0) return 1; if(b&1) { return (LL)sum(a,b/2)*(1+qpow(a,b/2+1))%MO; } else { return ((LL)sum(a,b/2-1)*(1+qpow(a,b/2))%MO+qpow(a,b))%MO; } } int a,b; int main() { scanf("%d%d", &a, &b); if(!a) {puts("0"); return 0;} LL ans=1; for(int i=2;i*i<=a;i++) { int cnt=0; if(!(a%i)) { a/=i, cnt++; while(!(a%i)) { a/=i,cnt++; } (ans*=sum(i,cnt*b))%=MO; } } if(a!=1) (ans*=sum(a,b))%=MO; printf("%lld\n", ans); return 0; }
标签:return,9901,int,MO,Sumdiv,1845,POJ,include,sum 来源: https://www.cnblogs.com/sahdsg/p/10645948.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。