poj1845 Sumdiv(数论,因数和,等比数列,快速幂)
来源:互联网 发布:java round up 编辑:程序博客网 时间:2024/05/16 13:02
Sumdiv
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 13333 Accepted: 3264
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).
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的所有因数和模余9901
#include<stdio.h>#define m 9901__int64 pow(__int64 p,__int64 r){//快速幂(***) __int64 s=1; while(r) { if(r%2) s=s*p%m; r/=2; p=p*p%m; } return s;}__int64 sum(__int64 p,__int64 r){//等比数列求和,取前一半做递归 if(!r) return 1; if(r%2)//数列个数为偶数,取数列前一半,乘法分配律 return (sum(p,r/2)*(1+pow(p,r/2+1)))%m; else//奇数个,中间一个单独加,其余与偶数个同理 return (sum(p,r/2-1)*(1+pow(p,r/2+1))+pow(p,r/2))%m;}int main(){ int a,b,i; int p[10000],r[10000]; while(scanf("%d%d",&a,&b)!=EOF) { int k=0; if(a%2==0) { p[k]=2; r[k]=0; while(a%2==0) { r[k]++; a/=2; } k++; }//将分解质因数,形如p[0]^r[0]*p[1]^r[1]*...*p[k-1]^r[k-1]; for(i=3; i*i<=a; i+=2)//质因子2单列出,后不再有偶质数 if(a%i==0) { p[k]=i; r[k]=0; while(a%i==0) { r[k]++; a/=i; } k++; } if(a!=1) { p[k]=a; r[k++]=1; }//剩余的大质数提出 int ans=1; for(i=0; i<k; i++) ans=((ans*(sum(p[i],r[i]*b)%m)))%m; /* 求所有因数的和: 生成函数 ∏(i=0,1,2...k-1)=∑[p[i]^j(0,1,2...r[i]*b)]; */ printf("%d\n",ans); } return 0;}
0 0
- poj1845 Sumdiv(数论,因数和,等比数列,快速幂)
- POJ1845 Sumdiv【因数之和】【二分求等比数列】
- POJ1845 Sumdiv【快速模幂+素因子分解+等比数列+二分法】
- (POJ1845)Sumdiv <约数和定理 + 快速幂求模 + 二分求等比数列和的模>
- poj1845——Sumdiv(数论+幂的因子和)
- 数论poj1845 因子和,等比数列求和
- [POJ1845]Sumdiv(数论+矩乘)
- poj1845 Sumdiv 数论
- 【数论】【poj1845】Sumdiv
- Sumdiv(数论综合模板题:快速分解因式+快速幂取模+约数和公式+递归二分求等比数列和)
- poj_1845 Sumdiv(素因子分解+快速幂+约数和+二分求等比数列和)
- poj 1845 Sumdiv(数论:欧拉函数+二分求等比数列前n项和+快速幂取模)
- POJ 1845 Sumdiv(质因数分解+快速幂+二分法求等比数列的和)
- POJ 1845-Sumdiv 数论 +快速幂&&筛素&&分解质因数&&求因数之和的模板
- Sumdiv(poj1845)(数学)
- poj 1845 Sumdiv 数论--等比数列和(逆元或者递归)
- poj1845 (数论+二分快速取模)
- POJ 1845 Sumdiv【同余模运算+递归求等比数列和+快速幂运算】
- 锁屏密码锁、图案锁忘记怎么办?简单利用adb删除(部分机型可用)
- UML-顺序图 (1)
- 空指针错误
- 如何从一个帧数有限的yuv文件获得更多帧数的文件
- NPM小结
- poj1845 Sumdiv(数论,因数和,等比数列,快速幂)
- 如何学好C++
- Android 如何反编绎APK文件&如何防止我们的代码被反编译
- 项目用到的sql
- Color Bash Prompt (简体中文)
- cocos2d-x luajit生成字节码
- access转sqlite——利用DBManager professional软件
- ubuntu设置eclipse+tomcat
- 链表的建立