POJ 1845 Sumdiv
来源:互联网 发布:景观施工图 软件 编辑:程序博客网 时间:2024/06/07 14:34
快速幂+等比数列求和。。。。
Sumdiv
Sumdiv
Time Limit: 1000MSMemory Limit: 30000KTotal Submissions: 12599Accepted: 3057
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).
The natural divisors of 8 are: 1,2,4,8. Their sum is 15.
15 modulo 9901 is 15 (that should be output).
Source
Romania OI 2002
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MOD=9901;
typedef long long int LL;
int p[10000],n[10000],k,A,B;
LL power(LL p,LL n) ///p^n
{
LL ans=1;
while(n>0)
{
if(n&1)
ans=(ans*p)%MOD;
n>>=1;
p=(p*p)%MOD;
}
return ans%MOD;
}
LL Spower(LL p,LL n) ///1+p^1+p^2+p^3+....+p^n-1+p^n
{
if(n==0) return 1;
if(n&1)
return ((Spower(p,n/2)%MOD)*((1+power(p,n/2+1))%MOD))%MOD;
else
return (((Spower(p,n/2-1)%MOD)*(1+power(p,n/2+1))%MOD)%MOD+power(p,n/2)%MOD)%MOD;
}
int main()
{
while(scanf("%d%d",&A,&B)!=EOF)
{
k=0;
for(int i=2;i*i<=A;)
{
if(A%i==0) p[k]=i,n[k]=0,k++;
while(A%i==0)
{
n[k-1]++;
A/=i;
}
if(i==2) i++;
else i+=2;
}
if(A!=1)
{
p[k]=A;
n[k++]=1;
}
LL ans=1;
for(int i=0;i<k;i++)
{
ans=(ans*Spower(p,B*n))%MOD;
}
printf("%I64d\n",ans);
}
return 0;
}
* This source code was highlighted by YcdoiT. ( style: Codeblocks )#include <cstdio>
#include <cstring>
using namespace std;
const int MOD=9901;
typedef long long int LL;
int p[10000],n[10000],k,A,B;
LL power(LL p,LL n) ///p^n
{
LL ans=1;
while(n>0)
{
if(n&1)
ans=(ans*p)%MOD;
n>>=1;
p=(p*p)%MOD;
}
return ans%MOD;
}
LL Spower(LL p,LL n) ///1+p^1+p^2+p^3+....+p^n-1+p^n
{
if(n==0) return 1;
if(n&1)
return ((Spower(p,n/2)%MOD)*((1+power(p,n/2+1))%MOD))%MOD;
else
return (((Spower(p,n/2-1)%MOD)*(1+power(p,n/2+1))%MOD)%MOD+power(p,n/2)%MOD)%MOD;
}
int main()
{
while(scanf("%d%d",&A,&B)!=EOF)
{
k=0;
for(int i=2;i*i<=A;)
{
if(A%i==0) p[k]=i,n[k]=0,k++;
while(A%i==0)
{
n[k-1]++;
A/=i;
}
if(i==2) i++;
else i+=2;
}
if(A!=1)
{
p[k]=A;
n[k++]=1;
}
LL ans=1;
for(int i=0;i<k;i++)
{
ans=(ans*Spower(p
}
printf("%I64d\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
- POJ 1845 Sumdiv
- POJ 1845 Sumdiv
- POJ 1845 Sumdiv
- POJ 1845 Sumdiv
- POJ 1845 Sumdiv
- poj 1845 Sumdiv 数论
- poj 1845 sumdiv
- POJ 1845 Sumdiv
- POJ 1845 Sumdiv
- poj 1845--Sumdiv
- 提升代码内外部质量的22条经验
- 『转』扩展欧几里德算法求不定方程
- POJ 3292 Semi-prime H-numbers
- Java 多线程设置线程超时时间之 Callable接口和Future接口
- 如何通过预加载器提升网页加载速度
- POJ 1845 Sumdiv
- POJ 2635 The Embarrassed Cryptographer
- 如何雇人的十五条建议
- HDOJ 1576 A/B
- 位图和SVG用法比较
- from QQ空间 to 博客园
- ASP.NET MVC 5 - 开始MVC5之旅
- POJ 1061 青蛙的约会
- POJ 2115 C Looooops
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
方便米
米类
米吧
纳奥米
马上有米
吓米
米啦
歌单
duomi
香菇多糖
多糖
黄芪多糖
真菌多糖
芝宁多糖
复合多糖
多糖铁
多糖乳清
多糖蛋白片
脂多糖
单糖和多糖
黏多糖
粘多糖
多糖有哪些
多糖是什么
多糖的作用
香菇菌多糖片
芝宁植物多糖
卡介菌多糖核酸注射液
香菇多糖注射剂
多糖铁复合物胶囊孕妇
介菌多糖核酸注射液
力蜚能多糖铁复合物胶囊
多糖铁复合胶囊
红源达多糖铁胶囊
多糖铁复合一般吃多久
香菇多糖胶囊
多糖铁复合物胶囊说明书
卡介菌多糖核酸
多黄酸粘多糖乳膏主要作用
香菇多糖的作用
芝宁多糖多少钱一盒