题目链接:传送门

题意:

求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. C#使用DirectoryEntry类操作Windows帐户

    1.创建windows帐户 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /// <summary> /// 创建Windows帐户 /// </summa ...

  2. 2014年国内最热门的.NET开源平台

    http://developer.51cto.com/art/201501/464292.htm

  3. AC日记——Oulipo poj 3461

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37958   Accepted: 15282 Description The ...

  4. 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 ...

  5. Redis 批量删除Redis的key 正则匹配删除

    del 删除单个key方便 要是删除多个就不是很方便了 这时候可以使用xsrsg来批量删除 1.退出redis 2.匹配CCPAI:开头的所有key*删除 redis-cli -a 密码 -h hos ...

  6. Xamarin XAML语言教程将XAML设计的UI显示到界面

    Xamarin XAML语言教程将XAML设计的UI显示到界面 如果通过XAML将UI设计好以后,就可以将XAML中的内容显示给用户了,也就是显示到界面上.由于创建XAML文件方式的不同,所以将XAM ...

  7. Python那些事

    Python这几年很火,在这里我用问答的方式来总结一下使用python的一些常见问题,对自己是个总结,也希望对有同样问题的朋友有帮助.   Q:Python为什么流行? A:Python是一个比较方便 ...

  8. hdu1061(C++)

    简单的找规律,不妨设N=10*x+a(a=N%10),那么N^N=(10*x+a)^N,用二项式展开定理可以知道N^N%10=a^N%10; 由于0<a<10,打表a^1,a^2,a^3, ...

  9. OpenCV机器学习库函数--SVM

    svm分类算法在opencv3中有了很大的变动,取消了CvSVMParams这个类,因此在参数设定上会有些改变. opencv中的svm分类代码,来源于libsvm. #include "o ...

  10. leetcode 46-Permutations and 47-Permutations II

    Permutations Given a collection of numbers, return all possible permutations. For example, [1,2,3] h ...