hdu 1452(因子和+逆元)
Happy 2004
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1393 Accepted Submission(s): 1018
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.
A test case of X = 0 indicates the end of input, and should not be processed.
10000
0
#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(因子和+逆元)的更多相关文章
- HDU 1452 Happy 2004 (逆元+快速幂+积性函数)
G - Happy 2004 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
- HDU 1452 欧拉定理
让你求$2004^x$所有因子之和,因子之和函数是积性函数$\sigma(n)=\sum_{d|n}d=\prod_{i=0}^{m}(\sum_{j=0}^{k_i}{P_i^{j}})$可用二项式 ...
- HDU 1452 (约数和+乘法逆元)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1452 题目大意:求2004^X所有约数和,结果mod 29. 解题思路: ①整数唯一分解定理: 一个 ...
- HDU 1452 Happy 2004(因子和的积性函数)
题目链接 题意 : 给你一个X,让你求出2004的X次方的所有因子之和,然后对29取余. 思路 : 原来这就是积性函数,点这里这里这里,这里讲得很详细. 在非数论的领域,积性函数指所有对于任何a,b都 ...
- 数学--数论--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 1452 Happy 2004(除数和函数,快速幂乘(模),乘法逆元)
Problem Description Considera positive integer X,and let S be the sum of all positive integer diviso ...
- HDU 1452
http://acm.hdu.edu.cn/showproblem.php?pid=1452 原来真心没见过这种题,不会做,非常帅 gcd(a,b)==1 && s(a,b)==s(a ...
- HDU 5976 数学,逆元
1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...
- hdu 2669 Romantic (乘法逆元)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
随机推荐
- Python数据类型的用法
字符串的用法 res = 'hellow,world' print(res) #res.显示的都是它的方法,下划线的除外 1 判断字符串的结尾字符,返回的值的布尔形式 endswith 判断字符串的开 ...
- django admin模块使用
BBS之admin组件的使用 1.创建超级管理员 创建超级管理员 一. tools>>>>runmanagepyTask>>>>>createsu ...
- 字符编码,ASCII、Unicode与UTF-8的理解
首先我们先要明白的两点是:1.计算机中的信息都是由二进制的0和1储存的:2.我们再计算机屏幕上看到的各种字符都是计算机系统按照一定的规则将二进制数字转换而来的. 一.基本概念. 1.字符集(chars ...
- 矩阵儿快速幂 - POJ 3233 矩阵力量系列
不要管上面的标题的bug 那是幂的意思,不是力量... POJ 3233 Matrix Power Series 描述 Given a n × n matrix A and a positive in ...
- 12、jQuery知识总结-2
1.避免冲突 jQuery 使用 $ 符号作为 jQuery 的简介方式 <html> <head> <script type="text/javascript ...
- Stephen 博客正式开通 【个人公众号:Stephen 】
个人博客开通. 个人公众号:Stephen
- sqlserver2008链接服务器中执行存储过程配置过程
参考:http://www.cnblogs.com/ycsfwhh/archive/2010/12/15/1906507.html 1.双方启动MSDTC服务MSDTC(分布式交易协调器),协调跨多个 ...
- sqlserver 取时间段重复或者不重复的数据
declare @str datetime, @end datetime select @str='2013-04-05',@end='2013-04-10'select * from arp_hbs ...
- Hibernate命名策略及配置
hibernate 表 命名策略 分类: hibernate2013-02-27 18:46464人阅读评论(0)收藏举报 Hibernate注释下的自定义架构实 ...
- 错误:支持“EFDbContext”上下文的模型已在数据库创建后发生更改。请考虑使用 Code First 迁移更新数据库(http://go.microsoft.com/fwlink/?LinkId
支持"EFDbContext"上下文的模型已在数据库创建后发生更改.请考虑使用 Code First 迁移更新数据库(http://go.microsoft.com/fwlink/ ...