题目链接:传送门

题意:

求2004^x的全部约数的和。

分析:

由唯一分解定理可知

x=p1^a1*p2^a2*...*pn^an

那么其约数和 sum = (p1^0+p1^1^…+p1^a1)*…* (pn^0+pn^1^…+pn )

代码例如以下:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio> using namespace std; const int mod = 29; int quick_mod(int a,int b){
int ans = 1;
while(b){
if(b&1) ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans;
} int fac[10],cnt;
int num[10];
void init(){
int n = 2004;
cnt = 0;
memset(num,0,sizeof(num));
for(int i=2;i*i<=n;i++){
if(n%i==0){
fac[cnt]=i;
while(n%i==0) n/=i,num[cnt]++;
cnt++;
}
}
if(n>1) fac[cnt]=n,num[cnt++]=1;
} int main()
{
int n;
while(~scanf("%d",&n)&&n){
init();
int ans = 1;
for(int i=0;i<cnt;i++){
num[i]*=n;
int inv = quick_mod(fac[i]-1,mod-2);
ans=ans*((quick_mod(fac[i],num[i]+1)-1+mod)*inv%mod)%mod;
}
printf("%d\n",ans);
}
return 0;
}

HDU 1452 Happy 2004(唯一分解定理)的更多相关文章

  1. HDU 1452 Happy 2004 (逆元+快速幂+积性函数)

    G - Happy 2004 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Subm ...

  2. HDU 3826 Squarefree number ( 唯一分解定理 )

    题目链接 题意 : 给出一个数.问其能不能被任何一个平方数整除.如果可以则输出 No 即不是 Square-free Number .否则输出 Yes 分析 : 首先 N 有 1e18 那么大.不能暴 ...

  3. hdu 1452 Happy 2004 膜拜这推导过程

    Happy 2004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. HDU 1452 Happy 2004(因子和的积性函数)

    题目链接 题意 : 给你一个X,让你求出2004的X次方的所有因子之和,然后对29取余. 思路 : 原来这就是积性函数,点这里这里这里,这里讲得很详细. 在非数论的领域,积性函数指所有对于任何a,b都 ...

  5. hdu 1452 Happy 2004

    因子和: 的因子是1,2,3,6; 6的因子和是 s(6)=1+2+3+6=12; 的因子是1,2,4,5,10,20; 20的因子和是 s(20)=1+2+4+5+10+20=42; 的因子是1,2 ...

  6. Hdu 1452 Happy 2004(除数和函数,快速幂乘(模),乘法逆元)

    Problem Description Considera positive integer X,and let S be the sum of all positive integer diviso ...

  7. HDU 1452 Happy 2004(因数和+费马小定理+积性函数)

    Happy 2004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  8. 数学--数论--Hdu 1452 Happy 2004(积性函数性质+和函数公式+快速模幂+乘法逆元)

    Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your ...

  9. HDU 6069 Counting Divisors(唯一分解定理+因子数)

    http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...

随机推荐

  1. 关于centos防火墙

    Centos升级到7之后,内置的防火墙已经从iptables变成了firewalld Centos7默认安装了firewalld,如果没有安装的话,可以使用 yum install firewalld ...

  2. ngrx/store effects 使用总结2:列表展示

    第一个计数器案例:http://www.cnblogs.com/axel10/p/8589122.html 完成了计数器案例后,现在开始比较能够完整的展示angular2+开发流程的案例:在线获取用户 ...

  3. Codeforces 629 B. Far Relative’s Problem

      B. Far Relative’s Problem   time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  4. 洛谷 P1478 陶陶摘苹果(升级版)【贪心/结构体排序/可用01背包待补】

    [链接]:https://www.luogu.org/problemnew/show/P1478 题目描述 又是一年秋季时,陶陶家的苹果树结了n个果子.陶陶又跑去摘苹果,这次她有一个a公分的椅子.当他 ...

  5. Codeforces 739B Alyona and a tree(树上路径倍增及差分)

    题目链接 Alyona and a tree 比较考验我思维的一道好题. 首先,做一遍DFS预处理出$t[i][j]$和$d[i][j]$.$t[i][j]$表示从第$i$个节点到离他第$2^{j}$ ...

  6. 洛谷——P2205 [USACO13JAN]画栅栏Painting the Fence

    题目描述 Farmer John has devised a brilliant method to paint the long fence next to his barn (think of t ...

  7. Cat Snuke and a Voyage --AtCoder

    题目描述 In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For conve ...

  8. OBS插件开发以及OBS插件的选择(obs直播插件)研究思路

    obs版本的选择: 工作室版,优化了很多东西,缺点是不能用插件,在部分机型不稳定,因为更新的很频繁.不过这个插件不能用的说法还是停留在早起,截至到今天已经完美支持,所以在不久的将来会越来越好,如果是开 ...

  9. MD5 algorithm in Objective C

    How to calculate the MD5 in objective C ? md5 is available on the iPhone and can be added as an exte ...

  10. 获取Android系统默认给每个app分配的内存上限

    ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); int ...