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. Oracle两种临时表的创建与使用详解

    ORACLE数据库除了可以保存永久表外,还可以建立临时表temporary tables.这些临时表用来保存一个会话SESSION的数据,或者保存在一个事务中需要的数据.当会话退出或者用户提交comm ...

  2. Flask初学者:URL(传参,请求,重定向)

    URL传参: 良好的URL:视图函数对应的url以/结尾是一种良好url,因为用户在访问的时候无论他有没有加上最后这个斜杠,都是能访问到的,相反,视图函数的url没有以/结尾,用户访问的时候却加上了这 ...

  3. python列表中的赋值与深浅拷贝

    首先创建一个列表 a=[[1,2,3],4,5,6] 一.赋值 a=[[1,2,3],4,5,6]b=aa[0][1]='tom'print(a)print(b)结果: [[1, 'tom', 3], ...

  4. 大数运算:HDU-1042-N!(附N!位数的计算)

    解题心得: 这里使用了10000进制.很明显,因为是n!所以单个最大的数是10000*10000,使用万进制. 可以借鉴高精度的加法,单个乘了之后在进位. 很坑的一点,0!=1,数学不好WA了三次,尴 ...

  5. P1605迷宫

    题目背景 迷宫 [问题描述] 给定一个N*M方格的迷宫,迷宫里有T处障碍,障碍处不可通过.给定起点坐标和 终点坐标,问: 每个方格最多经过1次,有多少种从起点坐标到终点坐标的方案.在迷宫 中移动有上下 ...

  6. greenplum-时间处理

    工作中遇到,需要改变两周以前的数据状态,于是查了下资料,原来数据库直接就可以处理,所以分享给大家! 在PostgreSQL中可以直接对时间进行加减运算:. SELECT now()::timestam ...

  7. volatile、synchronized、lock有什么区别,以及在哪些场景下使用哪种方式?

    [转]JVM锁机制volatile/synchronized/lock 1.volatile实现原理 (1)聊聊并发(一)——深入分析Volatile的实现原理 --硬件级别锁实现,Lock前缀指令会 ...

  8. Azure Active Directory中的特权身份管理如何运作?

    [TechTarget中国原创] 用户权限不是平等的.有些用户需要有大量权利和特权——通常这些都是管理员.企业在允许特权用户进行管理以及支持活动时,还需要意识到特权用户也有可能犯错.他们会犯错.他们可 ...

  9. 使用jQuery ui创建模态表单

    jQuery UI 是一个建立在 jQuery JavaScript 库上的小部件和交互库,可以使用它创建高度交互的 Web 应用程序. 在web页面的开发过程中,在添加元素的时候需要用到弹出窗口添加 ...

  10. Java的移位运算符

    1.左移运算符:<< 丢弃左边指定位数,右边补0. 注意: 当int类型进行左移操作时,左移位数大于等于32位操作时,会先求余(%)后再进行左移操作.也就是说左移32位相当于不进行移位操作 ...