数学--数论--Hdu 1452 Happy 2004(积性函数性质+和函数公式+快速模幂+乘法逆元)
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
设F(x)=2004x的因子和F(x)=2004^x的因子和F(x)=2004x的因子和 因为这是个积性函数,则有f(N)=∏i=1nf(qiqi)其中N可以表示为∏i=1nqiqif(N)=\prod_{i=1}^nf(q_i ^{q_i}) 其中 N可以表示为\prod_{i=1}^nq_i ^{q_i}f(N)=∏i=1nf(qiqi)其中N可以表示为∏i=1nqiqi
f(2004n)=f(2(2∗n))∗f(3n)∗f(167n)=(2(2∗n+1)−1)∗(3(n+1)−1)/2∗(167(n+1)−1)/166f(2004 ^ n)= f(2 ^{(2 * n)})* f(3 ^ n)* f(167 ^ n)
=(2 ^{(2 * n + 1)}-1)*(3 ^{(n + 1)}-1)/ 2 *(167 ^{(n + 1)}-1)/ 166f(2004n)=f(2(2∗n))∗f(3n)∗f(167n)=(2(2∗n+1)−1)∗(3(n+1)−1)/2∗(167(n+1)−1)/166
用到乘法逆元:(同余性质)
a ^ k / d = a ^ k *(d-1)d-1即为d的逆元。3的逆元为15 167的逆元为18
JAVA C++ 没区别,最近在JAVA要考试了额,熟悉一下。
import java.util.Scanner;
public class Main {
public static long Q_pow( long a, long p, long mod)
{
long ans = 1%mod;
while(p>0) {
if(p%2==1) ans = ans*a%mod; //防止在对P取模前溢出
a = a*a%mod;
p >>=1; //比除法快多了
}
return ans;
}
public static void main(String[] args) {
int n;
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
n=in.nextInt();
if(n==0) break;
long ans=((Q_pow(167,n+1,29)-1)*18)%29;
ans=(ans*((Q_pow(3,n+1,29)-1)*15)%29)%29;
ans=(ans*(Q_pow(2,2*n+1,29)-1))%29;
System.out.println(ans);
}
in.close();
}
}
数学--数论--Hdu 1452 Happy 2004(积性函数性质+和函数公式+快速模幂+乘法逆元)的更多相关文章
- 数学--数论--HDU1825(积性函数性质+和函数公式+快速模幂+非互质求逆元)
As we all know, the next Olympic Games will be held in Beijing in 2008. So the year 2008 seems a lit ...
- 数学--数论--HDU - 6395 Let us define a sequence as below 分段矩阵快速幂
Your job is simple, for each task, you should output Fn module 109+7. Input The first line has only ...
- HDU 1452 Happy 2004 (逆元+快速幂+积性函数)
G - Happy 2004 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
- HDU 1452 Happy 2004(因子和的积性函数)
题目链接 题意 : 给你一个X,让你求出2004的X次方的所有因子之和,然后对29取余. 思路 : 原来这就是积性函数,点这里这里这里,这里讲得很详细. 在非数论的领域,积性函数指所有对于任何a,b都 ...
- HDU 1452 Happy 2004(因数和+费马小定理+积性函数)
Happy 2004 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- hdu 1452 Happy 2004
因子和: 的因子是1,2,3,6; 6的因子和是 s(6)=1+2+3+6=12; 的因子是1,2,4,5,10,20; 20的因子和是 s(20)=1+2+4+5+10+20=42; 的因子是1,2 ...
- Hdu 1452 Happy 2004(除数和函数,快速幂乘(模),乘法逆元)
Problem Description Considera positive integer X,and let S be the sum of all positive integer diviso ...
- 【BZOJ 2749】 2749: [HAOI2012]外星人 (数论-线性筛?类积性函数)
2749: [HAOI2012]外星人 Description Input Output 输出test行,每行一个整数,表示答案. Sample Input 1 2 2 2 3 1 Sample Ou ...
- 数学--数论--HDU 12151七夕节 Plus (因子和线性筛)
Problem Description 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" ...
随机推荐
- 会 python 的一定会爬虫吗,来看看
文章更新于:2020-02-18 注:python 爬虫当然要安装 python,如何安装参见:python 的安装使用和基本语法 一.什么是网络爬虫 网络爬虫就是用代码模拟人类去访问网站以获取我们想 ...
- Jenkins构建项目后发送钉钉消息推送
前言 钉钉是我们日常工作的沟通工具,在Jenkins构建持续集成项目配合钉钉机器人的功能,可以让我们在持续集成测试环节快速接收到测试结果的消息推送. 一:新建一个钉钉群,选择自定义机器人 二:添加机器 ...
- 从谷歌面试翻车到offer收割的心路历程
首先声明,这只是我的播客随感,其中无法避免有一些个人色彩的见解,请不要在意,我尊敬任何的互联网公司,尊敬研究生期间的老师同学,我只希望给在求学路上的CS同学一些启发. 先介绍一下背景,我是ACM铜牌退 ...
- MySQL锁---InnoDB行锁需要注意的细节
前言 换了工作之后,接近半年没有发博客了(一直加班),emmmm.....今天好不容易有时间,记录下工作中遇到的一些问题,接下来应该重拾知识点了.因为新公司工作中MySQL库经常出现查询慢,锁等待,节 ...
- Retrofit 网络访问框架简单使用
1.引入远程依赖:包括okhttp;retrofit2;retrofit的GSON解析器 compile'com.squareup.okhttp3:okhttp:3.2.0' compile'com. ...
- 亲测可以使用的Axmath和MathPix插入word公式
Axmath破解版链接 链接:https://pan.baidu.com/s/1Phak8mc3msKAMQ6H_5EN5g 提取码:glti MathPixTool和Axmath共同使用向word插 ...
- A. Number Theory Problem
题目大意:计算小于2^n,且满足2^k-1并且是7的倍数的个数 思路:优先打表,数据不大,1e5,然后求个前n项和 #include<bits/stdc++.h> using namesp ...
- mybatis源码学习:从SqlSessionFactory到代理对象的生成
目录 一.根据XML配置文件构建SqlSessionFactory 二.通过SqlSessionFactory创建SqlSession 三.getMapper获取动态代理对象 一.根据XML配置文件构 ...
- 【Vue】状态管理
页面应用需要Vuex管理全局/模块的状态,大型单页面组件如果靠事件(events)/属性(props)通讯传值会把各个组件耦合在一起.因 此需要Vuex统一管理,当然如是小型单页面应用,引用Vuex反 ...
- TensorFlow keras dropout层
# 建立神经网络模型 model = keras.Sequential([ keras.layers.Flatten(input_shape=(28, 28)), # 将输入数据的形状进行修改成神经网 ...