HDU 1452 Happy 2004(唯一分解定理)
题目链接:传送门
题意:
求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(唯一分解定理)的更多相关文章
- HDU 1452 Happy 2004 (逆元+快速幂+积性函数)
G - Happy 2004 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
- HDU 3826 Squarefree number ( 唯一分解定理 )
题目链接 题意 : 给出一个数.问其能不能被任何一个平方数整除.如果可以则输出 No 即不是 Square-free Number .否则输出 Yes 分析 : 首先 N 有 1e18 那么大.不能暴 ...
- hdu 1452 Happy 2004 膜拜这推导过程
Happy 2004 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 1452 Happy 2004(因子和的积性函数)
题目链接 题意 : 给你一个X,让你求出2004的X次方的所有因子之和,然后对29取余. 思路 : 原来这就是积性函数,点这里这里这里,这里讲得很详细. 在非数论的领域,积性函数指所有对于任何a,b都 ...
- 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 ...
- Hdu 1452 Happy 2004(除数和函数,快速幂乘(模),乘法逆元)
Problem Description Considera positive integer X,and let S be the sum of all positive integer diviso ...
- HDU 1452 Happy 2004(因数和+费马小定理+积性函数)
Happy 2004 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- 数学--数论--Hdu 1452 Happy 2004(积性函数性质+和函数公式+快速模幂+乘法逆元)
Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your ...
- HDU 6069 Counting Divisors(唯一分解定理+因子数)
http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...
随机推荐
- 对/proc和/sys的一些理解
一切皆文件,设备(文件)可以通过读写来操作:/proc procfs:/sys sysfs: 个人的理解(不知对不对,感觉有些片面)/proc是内存中有关系统进程的实时信息:/sys是有关系统内核以及 ...
- hdu 2739(尺取法)
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22876 ...
- hdu 4995(离散化下标+模拟)
Revenge of kNN Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- function in Postgres
CREATE or REPLACE FUNCTION fn_attr_category() RETURNS void AS $BODY$ declare v_tmp_rec record; begin ...
- Educational Codeforces Round 34 B. The Modcrab【模拟/STL】
B. The Modcrab time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- HDU 1005 Number Sequence【斐波那契数列/循环节找规律/矩阵快速幂/求(A * f(n - 1) + B * f(n - 2)) mod 7】
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- ansible 通过网络下载和上传文件
1.通过http下载文件,并且不验证证书 - name: download files by https get_url: url: https://robin.org.cn/test.zip des ...
- java 两个int类型的数据相除并输出百分号保留两位有效数字
java代码: public void IntA(int a , int b){ //首先判断分母不能为0 if(b!=0){ folat num = (float) a*100/b; Decimal ...
- sslstrip 中间人HTTP
https://moxie.org/software.html http://bbs.pediy.com/thread-173970.htm https://www.cnblogs.com/index ...
- ios获得文件字节总数
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.finalPath err ...