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(因数和+费马小定理+积性函数)的更多相关文章

  1. 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; ...

  2. 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)

    题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...

  3. hdu 4869 Turn the pokers(组合数+费马小定理)

    Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...

  4. HDU——5667Sequence(矩阵快速幂+费马小定理应用)

    Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total S ...

  5. HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)

    Sum Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  6. 数学--数论--HDU 1098 Ignatius's puzzle (费马小定理+打表)

    Ignatius's puzzle Problem Description Ignatius is poor at math,he falls across a puzzle problem,so h ...

  7. 数论初步(费马小定理) - Happy 2004

    Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...

  8. 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum

    Sum Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...

  9. HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description   Sample Input 2 Sample Outp ...

随机推荐

  1. 使用ENCKEYS方法加密数据

    要使用这种数据加密方法,您需要配置Oracle GoldenGate以生成加密密钥并将密钥存储在本地ENCKEYS文件中.此方法使用的永久密钥只能通过根据使用加密密钥填充ENCKEYS文件中的说明重新 ...

  2. $resource详解

    $resource 首先添加$resource的引用 <script src="Scripts/angular.min.js"></script> < ...

  3. 【MongoDB】 Failed to connect to 127.0.0.1:27017, reason: Connection refused

    由于项目需要,在一台虚拟机上安装了MongoDB,但是在启动的时候,出现如下错误: [root@localhost bin]# ./mongo MongoDB shell version v3.4.0 ...

  4. C# 基础之string[,] 和string[][]

    昨天做项目时碰到一个问题,后台返回一张关系表,里面就两个字段,简化为A,B字段(1:N的关系),一个A对应多个B字段. 由于对于string[,] 和string[][] 的认识不到位,刚开始搞错了数 ...

  5. java.sql.SQLException: Column count doesn't match value count at row 1 解决办法

    ♦ 所存储的数据与数据库表的字段类型定义不匹配. ♦ 解决办法: 检查dao层(数据访问层)的sql语句中赋值的参数是否与数据库中的字段个数.字段类型一致.

  6. linux系统常用运维命令

    目录/文件处理命令 mkdir dirname         创建文件夹 mkdir -p /tmp/a/b         递归创建目录 rm -rf dirname         删除目录及内 ...

  7. you-get 2017-06-02

    可下载优酷土豆的1080p视频 修订版本 针对最近优酷土豆升级后无法下载的问题进行修改 需要安装 python3 和 ffmpeg http://pan.baidu.com/s/1c2hBCe0

  8. 删除元素splice、shift\pop

      splice() 方法: 向/从数组中添加/删除项目,然后返回被删除的项目. splice( index位数, 数量, 新添加 ) 该方法会改变原始数组 删除数组中第一个元素 arr.shift( ...

  9. ES--05

    第四十一讲!分词器内部组成 内置分词器 课程大纲 1.什么是分词器 切分词语,normalization(提升recall召回率) 给你一段句子,然后将这段句子拆分成一个一个的单个的单词,同时对每个单 ...

  10. MySQL的数据文件存储

    MySQL的数据文件存储 MyISAM引擎分为:静态.动态和压缩MyISAM三种: 静态MyISAM:如果数据表中的各数据列的长度都是预先固定好的,服务器将自动选择这种表类型.因为数据表中每一条记录所 ...