HDU 1452 Happy 2004(因数和+费马小定理+积性函数)
Happy 2004
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2183 Accepted Submission(s): 1582
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
Source
ACM暑期集训队练习赛(六)
Recommend
lcy | We have carefully selected several similar problems for you: 1695 1788 1060 1370 1211
题解:
1.积性函数:函数f如果满足对于任意两个互质的正整数m和n,均有f(mn)=f(m)f(n),就称f为积性函数(或乘性函数)。如果对于任意两个正整数m和n,均有f(mn)=f(m)f(n),就称为完全积性函数。
2.因数和函数:
3.因数和函数为积性函数,结合费马小定理:
#include<iostream>
using namespace std;
int mul(int a,int x){
int ans=1;
while(x){
if(x&1)
ans=a*ans%29;
x>>=1;
a=a*a%29;
}
return ans;
}
int main()
{
int x;
while(~scanf("%d",&x)&&x)
{
int ans1=(mul(2,2*x+1)-1)%29;
int ans2=(mul(3,x+1)-1)%29*mul(2,27)%29;
int ans3=(mul(22,x+1)-1)%29*mul(21,27)%29;
printf("%d\n",ans1*ans2*ans3%29);
}
return 0;
}
HDU 1452 Happy 2004(因数和+费马小定理+积性函数)的更多相关文章
- HDU 5667 Sequence 矩阵快速幂+费马小定理
题目不难懂.式子是一个递推式,并且不难发现f[n]都是a的整数次幂.(f[1]=a0;f[2]=ab;f[3]=ab*f[2]c*f[1]...) 我们先只看指数部分,设h[n]. 则 h[1]=0; ...
- 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)
题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...
- hdu 4869 Turn the pokers(组合数+费马小定理)
Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...
- HDU——5667Sequence(矩阵快速幂+费马小定理应用)
Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total S ...
- HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)
Sum Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 数学--数论--HDU 1098 Ignatius's puzzle (费马小定理+打表)
Ignatius's puzzle Problem Description Ignatius is poor at math,he falls across a puzzle problem,so h ...
- 数论初步(费马小定理) - Happy 2004
Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...
- 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum
Sum Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...
- HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description Sample Input 2 Sample Outp ...
随机推荐
- 图片转换base64编码,点击div的时候选择文件
有时候我们希望文件上传的时候预览图片,下面插件可以实现上传前预览图片 (也可以提取文件的base64编码) max-height: 140px;max-width: 120px;可以指定图片的最大宽度 ...
- android中常用的优秀功能 (AsyncTask)
1.用好 AsyncTask 一个优秀的android app,肯定少不了一个很好的用户体验,除了界面等外,流畅的交互,快速响应的速度都是至关重要,若 是加载一个数据,都得等上几秒钟,怕是app卸载率 ...
- Netty实现简单UDP服务器
本文参考<Netty权威指南> 文件列表: ├── ChineseProverbClientHandler.java ├── ChineseProverbClient.java ├── C ...
- linux 终端命令行的快捷键列表
终端有很多快捷键,不太好记,常用的在这里 Ctrl+r 实现快速检索使用过的历史命令.Ctrl+r中r是retrieve中r.Ctrl+a:光标回到命令行首. (a:ahead)Ctrl+e:光标回到 ...
- AI 玩法整理
随着信息技术的火热发展,人工智能已经成为IT全行业的风口爆发点,既然风口来了,作为技术人人员也都毫不犹豫的分一杯羹,怎么玩呢? 接下来的博客就会带领大家一起玩玩AI 认识AI--略,如果有需要的可以再 ...
- 【转】HTTP
[转]HTTP 一.http概述 超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必须遵守这个标准.设计HTT ...
- ES6学习笔记八(module模块export)
1.导出export,导入import组合 知识点1:导出export lesson2.js export let A=; export function test(){ console.log('t ...
- InstallShield 静默安装
可能先需要获取安装包参数,安装包参数获取/?或是/HELP InstallScrip工程 1. 在命令行窗口中使用 -R 参数(即record) 运行安装程序. 例如: Setup.exe -R or ...
- 发布自己的类库到NuGet
NuGet是一个为大家所熟知的Visual Studio扩展,通过这个扩展,开发人员可以非常方便地在Visual Studio中安装或更新项目中所需要的第三方组件,同时也可以通过NuGet来安装一些V ...
- InnoDB 与 MYISAM的区别和联系
1.存储引擎是什么? MySQL中的数据用各种不同的技术存储在文件(或者内存)中.这些技术中的每一种技术都使用不同的存储机制.索引技巧.锁定水平并且最终提供广泛的不同的功能和能力.通过选择不同的技术, ...