Happy 2004

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1393    Accepted Submission(s): 1018

Problem Description
Consider
a positive integer X,and let S be the sum of all positive integer
divisors of 2004^X. Your job is to determine S modulo 29 (the rest of
the division of S by 29).

Take X = 1 for an example. The positive
integer divisors of 2004^1 are 1, 2, 3, 4, 6, 12, 167, 334, 501, 668,
1002 and 2004. Therefore S = 4704 and S modulo 29 is equal to 6.

 
Input
The input consists of several test cases. Each test case contains a line with the integer X (1 <= X <= 10000000).

A test case of X = 0 indicates the end of input, and should not be processed.

 
Output
For each test case, in a separate line, please output the result of S modulo 29.
 
Sample Input
1
10000
0
 
Sample Output
6 10
n的因子和为s(n)
令g(p, e) = (p^(e+1) - 1) / (p-1),则s(n) = g(p1, e1) * g(p2, e2) * ... * g(pk, ek)
 
这个题只不过是求nx的因子和而已,假设 n = p1e1p2e2...pnen 那么 nx=p1e1*xp2e2*x...pnen*x  由于这题x的范围比较大,所以要用快速取模,又因为这题有除法取模,而模的数又是一个质数,所以要用到逆元.
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <queue>
using namespace std;
typedef long long LL;
const int N = ;
LL p[]={,,};
LL e[]={,,};
LL extend_gcd(LL a,LL b,LL &x,LL &y){
if( b == ) {
x = ;
y = ;
return a;
}
else{
LL x1,y1;
LL d = extend_gcd(b,a%b,x1,y1);
x = y1;
y= x1-a/b*y1;
return d;
}
}
LL mod_reverse(LL a,LL n)
{
LL x,y;
LL d=extend_gcd(a,n,x,y);
if(d==) return (x%n+n)%n;
else return -;
}
LL pow_mod(LL a,LL n,LL mod){
LL ans = ;
while(n){
if(n&) ans = ans*a%mod;
a= a*a%mod;
n=n>>;
}
return ans;
}
LL g(LL p,LL e){
LL inv = mod_reverse(p-,);
LL ans = (inv*(pow_mod(p,e+,)-))%;
return ans;
}
int main()
{
LL n;
while(scanf("%lld",&n)!=EOF,n){
LL m = ;
LL sum = ;
for(int i=;i<;i++){
sum = (sum*g(p[i],e[i]*n))%;
}
printf("%lld\n",sum);
}
return ;
}

hdu 1452(因子和+逆元)的更多相关文章

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

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

  2. HDU 1452 欧拉定理

    让你求$2004^x$所有因子之和,因子之和函数是积性函数$\sigma(n)=\sum_{d|n}d=\prod_{i=0}^{m}(\sum_{j=0}^{k_i}{P_i^{j}})$可用二项式 ...

  3. HDU 1452 (约数和+乘法逆元)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1452 题目大意:求2004^X所有约数和,结果mod 29. 解题思路: ①整数唯一分解定理: 一个 ...

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

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

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

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

  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

    http://acm.hdu.edu.cn/showproblem.php?pid=1452 原来真心没见过这种题,不会做,非常帅 gcd(a,b)==1 && s(a,b)==s(a ...

  8. HDU 5976 数学,逆元

    1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...

  9. hdu 2669 Romantic (乘法逆元)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

随机推荐

  1. JAVA解析XML有哪几种方法?并简述各自的优缺点

    DOM: 是用与平台和语言无关的方式表示XML文档的官方W3C标准,分析该结构通常需要加载整个文档和构造层次结构,然后才能做任何工作.是基于信息层次的 优点有:由于树在内存中是持久的,因此可以修改它以 ...

  2. astyle 使用说明 —— 集成到开发平台中

    转自:https://www.cnblogs.com/jiangxinnju/p/4908575.html 欢迎关注我的社交账号: 博客园地址: http://www.cnblogs.com/jian ...

  3. input type=file输入框

    <div class="row"> <!--选择图片按钮--> <div class="col-xs-12" align=&quo ...

  4. 使用Spark Streaming + Kudu + Impala构建一个预测引擎

    随着用户使用天数的增加,不管你的业务是扩大还是缩减了,为什么你的大数据中心架构保持线性增长的趋势?很明显需要一个稳定的基本架构来保障你的业务线.当你的客户处在休眠期,或者你的业务处在淡季,你增加的计算 ...

  5. OpenCV学习笔记(二) cv::Mat

    部分内容转自:OpenCV Tuturial,ggicci 在OpenCV Tuturial中可查看Mat的初始化与打印方法. Mat本质上是由两个数据部分组成的类: 矩阵头(包含矩阵尺寸,存储方法, ...

  6. Retrofit 入门和提高

    首先感谢这个哥们,把我从helloworld教会了. http://blog.csdn.net/angcyo/article/details/50351247 retrofit 我花了两天的时间才学会 ...

  7. navicat常用快捷键及注意事项

    常用快捷键: 1. ctrl + q: 打开新查询窗口 2. ctrl + r: 运行当前窗口内的所有语句 3. ctrl + w: 关闭当前窗口 4. F6: 打开一个mysql命令行窗口 ---- ...

  8. Maven使用入门

    Maven使用POM文件管理项目资源,pom.xml文件位于项目根目录下,结构如下: <?xml version="1.0" encoding="UTF-8&quo ...

  9. MySQL时间字段究竟使用INT还是DateTime

    今天解析DEDECMS时发现deder的MYSQL时间字段,都是用 `senddata` ) unsigned '; 随后又在网上找到这篇文章,看来如果时间字段有参与运算,用int更好,一来检索时不用 ...

  10. 云中Active Directory是如何工作的?

    [TechTarget中国原创] 微软公司1999年在Windows Server 2000中引入Active Directory功能.后期的Windows Server版本中陆续进行改善提升,Win ...