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 ...
随机推荐
- JAVA运行环境配置
win10下,右击我的电脑-->高级系统设置-->高级-->环境变量-->系统变量 1新建 变量名 JAVA_HOME 变量值 C:\Program Files\Jav ...
- Linux程序编辑器习题汇总
简答题部分: 1.我用vi开启某个档案后,要在第34行向右移动15个字符,应该在一般模式中下达什么指令? (1)先按下34G到34行:(2)再按下[l5+向右键],或[l5l]亦可! 2.在vi开启的 ...
- 关于前后端日期处理 开发注意事项 jquery.tmpl()函数的使用
1当后端将日期传到前段的时候 我们通常会需要将日期转为制定格式 除了平常我们使用的前段插件将日期转好 spring @datetimeFormat 注解 这些形式外 我们还可以在实体里通过get方法进 ...
- loj2059 「TJOI / HEOI2016」字符串
字符串好难啊不会啊 #include <iostream> #include <cstdio> using namespace std; int n, m, rnk[10000 ...
- 微信公众开发api接口
简介 微信公众平台消息接口为开发者提供了一种新的消息处理方式.微信公众平台消息接口为开发者提供与用户进行消息交互的能力.对于成功接入消息接口的微信公众账号,当用户发消息给公众号,微信公众平台服务器 ...
- Xmanager用法(export DISPLAY=客户端IP:0.0)
1.在用户的目录下找到文件.bash_profile或profile,用vi对其进行编辑.加入下列命令行: DISPLAY=192.168.88.71:0.0;export DISPLAY 2.如果只 ...
- IntelliJ IDEA下maven Spring MVC配置
1. 导入工程:或者新建Spring web工程,可以参考博客中的Eclipse Spring MVC的方式: 2.配置Tomcat服务器,有两种方式:一是配置maven插件,而是配置本地Tomcat ...
- 聊聊、Java 命令 第一篇
网上很多讲 Javac 和 Java 命令的,我觉得还是要自己写一写,做一个自己的总结,也方便以后查询. 开始之前先看看 help 命令,基本上任何一个软件都会提供这个命令. 没有什么比 -help ...
- [python][django 1.10中文文档]
https://docs.djangoproject.com/en/1.10/ 官方文档,点我下载 推荐一个翻译django 1.8.2的网址: 推荐一个翻译django 1.10的博客:(着重推荐 ...
- webpack vue-cli 常见问题总结
1. webpack打包压缩 ES6 js..vue报错: ERROR in js/test.js from UglifyJs Unexpected token punc ?(?, expected ...