PKU_1845 Sumdiv

64 篇文章 0 订阅
54 篇文章 0 订阅
http://acm.pku.edu.cn/JudgeOnline/problem?id=1845
Sumdiv
Time Limit: 1000MS
Memory Limit: 30000K
Total Submissions: 2659
Accepted: 461

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

Romania OI 2002
思路很简单就是暴力,只要注意下中间过程取mod的时候
1.对a分解素数,得到pi,ci分别表示第i个素因子和它的个数
2.ci*b,就是a^b=p1^(c1*b) * .... * pi^(ci*b)
3.所求的就是ans=(1+p1+p1^2+...+p1^(c1*b))*()...*(1+pi+pi^2+...+pi^(ci*b))
4.由于b 比较大,所以求1+p1+p1^2+...+p1^(c1*b)的时候使用二分,要注意取mod,小心溢出
以下是参考代码
  1. #include <iostream>
  2. using namespace std;
  3. typedef unsigned long long llong;
  4. int p[4000],len=0,top[32][2],tlen;
  5. bool s[7072]={true,true};
  6. void split(llong n)
  7. {
  8.     tlen=0;
  9.     int i;
  10.     for(i=0;i<len;i++)
  11.         {
  12.             if(n%p[i]==0)
  13.                 {
  14.                     top[tlen][0]=0;
  15.                     top[tlen][1]=p[i];
  16.                     while(n%p[i]==0)
  17.                         {
  18.                             top[tlen][0]++;
  19.                             n/=p[i];
  20.                         }
  21.                     tlen++;
  22.                     if(n==1||(n<=7071&&!s[n]))break;
  23.                 }
  24.         }
  25.     if(n!=1){top[tlen][0]=1;top[tlen++][1]=n;}
  26. }
  27. llong sum(int n,llong k)
  28. {
  29.     if(k==1)return 1;
  30.     llong tmp=sum(n,k/2);
  31.     if(k&0x1)
  32.         return (tmp%9901+pow_mod(n,k/2,9901)+pow_mod(n,k/2+1,9901)*tmp)%9901;
  33.     return (tmp%9901+pow_mod(n,k/2,9901)*tmp)%9901;
  34. }
  35. int main()
  36. {
  37.     llong a,b,ans;
  38.     int i,j;
  39.     for(i=2;i<=84;i++)if(!s[i])for(j=i;j*i<=7071;j++)s[i*j]=true;
  40.     for(i=2;i<=7071;i++)if(!s[i])p[len++]=i;
  41.     while(cin>>a>>b)
  42.         {
  43.             ans=1;
  44.             split(a);
  45.             for(i=0;i<tlen;i++)
  46.                 {
  47.                     ans*=sum(top[i][1],top[i][0]*b+1);
  48.                     ans%=9901;
  49.                 }
  50.             cout<<ans<<endl;
  51.         }
  52.     return 0;
  53. }
其中pow_mod就是a^b mod c的函数,这里不列出了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值