POJ 1845 Sumdiv (大数据因子和)
来源:互联网 发布:绝地求生加速器 知乎 编辑:程序博客网 时间:2024/04/30 00:17
Sumdiv
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 17287 Accepted: 4343
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=p1^k1*p2^k2*...*pn^kn,所以说A^B=p1^(k1*B)*p2^(k2*B)*...*pn^(kn*B),所以说根据因子和公式得(1+p1+p1^2+...+p1^(k1*B))*(1+p2+p2^2+...+p2^(k2*B))*...*(1+pn+pn^2+...+pn^(kn*B)),结果就是一个个等比数列的乘积,但是数据是5e8,这样直接按照等比数列的求和公式写会超时或者RE,所以说要优化等比数列求和,用折半二分递归的方法求等比数列的和,这里就先不说了,等后来总结的时候再深究。
ac代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<set>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 100010#define LL long long#define ll __int64#define INF 0x7fffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)#define eps 1e-10using namespace std;int gcd(int a,int b){return b?gcd(b,a%b):a;}int lcm(int a,int b){return a/gcd(a,b)*b;}LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}//headstruct s{int num;int cnt;}p[MAXN];int fun(int a,int n,int MOD){if(n==0)return 1;if(n%2)return ((1+powmod(a,n/2+1,MOD))%MOD*fun(a,n/2,MOD)%MOD)%MOD;elsereturn (powmod(a,n/2,MOD)+(1+powmod(a,n/2+1,MOD))%MOD*fun(a,(n-1)/2,MOD)%MOD)%MOD;}int main(){int a,b,i;while(scanf("%d%d",&a,&b)!=EOF){int x=a;int ccnt=0;for(i=2;i*i<=x;i++){if(x%i==0){p[ccnt].num=i;int t=0;while(x%i==0) x/=i,t++;p[ccnt++].cnt=t;}if(x==1)break;}if(x!=1){p[ccnt].num=x;p[ccnt].cnt=1;ccnt++;}LL ans=1;for(i=0;i<ccnt;i++)ans=(ans*fun(p[i].num,p[i].cnt*b,9901))%9901;printf("%d\n",ans);}return 0;}
0 0
- POJ 1845 Sumdiv (大数据因子和)
- POJ 1845 Sumdiv (因子和)
- POJ 1845 Sumdiv(因子和 大数模 费马小定理)
- POJ 1845 Sumdiv (因子和)
- POJ 1845-Sumdiv【经典数学题目---求因子和】
- poj-1845 Sumdiv (逆元+费马小定理+因子和)
- POJ 1845 Sumdiv 求幂级数的因子和+二分
- poj-1845 Sumdiv && nyoj - 928 小M的因子和
- POJ 1845 Sumdiv(求阶乘的因子和)
- poj 1845 Sumdiv ,质因子分解
- poj 1845 Sumdiv (算术基本定理求一个数因子和)
- poj 1845 Sumdiv(二分递归求等比数列+素因子分解)
- [ACM] POJ 1845 Sumdiv(求A的B次方的所有因子的和,一大堆数学公式...,可做模板)
- poj 1845 Sumdiv 矩阵法求幂的和
- POJ 1845 Sumdiv (数论,约数和)
- A^B所有因子和(poj1845 Sumdiv)
- POJ 1845 Sumdiv
- poj 1845-Sumdiv
- Redis入门很简单之一【简介与环境搭建】
- 电脑装机的十大误区,你中招了吗?
- BZOJ 1121 & science
- LayoutInflater作用
- Redis入门很简单之二【常见操作命令】
- POJ 1845 Sumdiv (大数据因子和)
- Redis入门很简单之三【常见参数配置】
- Redis入门很简单之四【初识Jedis】
- 【POJ】[1417]True Liars
- shell程序设计(二)
- Codeforces Round #342 (Div. 2) 总结
- swift 报错
- ubuntu 安装dnw 适用于6410和2410
- Redis入门很简单之五【Jedis和Spring的整合】