HDU 1452 Happy 2004 求2004^n的所有因子和 积性函数应用

题目链接:点击打开链接

百度个题解:点击打开链接

6的因子是1,2,3,6; 6的因子和是 s(6)=1+2+3+6=12;

20的因子是1,2,4,5,10,20; 20的因子和是 s(20)=1+2+4+5+10+20=42;

2的因子是1,2; 2的因子和是 s(2)=1+2=3;

3的因子是1,3; 3的因子和是 s(3)=1+3=4;

4的因子和是 s(4)=1+2+4=7;

5的因子和是 s(5)=1+5=6;

s(6)=s(2)*s(3)=3*4=12;

s(20)=s(4)*s(5)=7*6=42;

这是巧合吗?

再看 s(50)= 1+2+5+10+25+50=93=3*31=s(2)*s(25),s(25)=1+5+25=31.

这在数论中叫积性函数,当gcd(a,b)=1时 s(a*b)=s(a)*s(b);

如果p是素数

s(p^n)=1+p+p^2+...+p^n= (p^(n+1)-1) /(p-1) (1)

例 hdu1452 Happy 2004

计算 因子和 s(2004^X) mod 29 ,

2004=2^2 *3 *167

s(2004^X) ) = (s(2^2X))) * (s(3^X))) * (s(167^X)))

167)=22;

s(2004^X) ) = (s(2^2X))) * (s(3^X))) * (s(22^X)))

a=s(2^2X)=(2^(2X+1)-1) //根据 (1)

b=s(3^X)= (3^(X+1)-1)/2 //根据 (1)

c=s(22^X)= (22^(X+1)-1)/21 //根据 (1)

%运算法则 1. (a*b) %p= ( a%p)
*(b%p)

%运算法则 2. (a/b) %p= ( a *b^(-1)%p)

b^(-1)是 b的逆元素 (%p)

2的逆元素是15 ())
,因为2*15=30 % 29=1 % 29

21的逆元素是18 ())
,因为21*18=378% 29 =1 % 29

因此

a=(powi(2,2*x+1,29)-1)% 29;

b=(powi(3,x+1,29)-1)*15 % 29;

c=(powi(22,x+1,29)-1)*18 % 29;

ans=(a*b)% 29*c % 29;

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <vector>
#include <string>
#include <time.h>
#include <math.h>
#include <iomanip>
#include <queue>
#include <stack>
#include <set>
#include <map>
const int inf = 1e8;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T>
inline bool rd(T &ret) {
	char c; int sgn;
	if (c = getchar(), c == EOF) return 0;
	while (c != '-' && (c<'0' || c>'9')) c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
	ret *= sgn;
	return 1;
}
template <class T>
inline void pt(T x) {
	if (x <0) { putchar('-'); x = -x; }
	if (x>9) pt(x / 10);
	putchar(x % 10 + '0');
}
using namespace std;
const int mod = 29;
int Pow(int x, int y){
	int ans = 1;
	while (y){
		if (y & 1)ans = ans*x%mod;
		y >>= 1;
		x = x*x%mod;
	}
	return ans;
}
int n;//2004= 2*2*3*167
int gao(int x, int y){
	int ans = Pow(x, y + 1) - 1;
	while (ans % (x - 1))ans += mod;
	ans /= x - 1;
	return ans%mod;
}
int main(){
	while (cin>>n, n){
		int ans = gao(2, 2 * n) * gao(3, n) * gao(167, n);
		cout << ans % mod<< endl;
	}
	return 0;
}
时间: 2024-08-28 18:23:08

HDU 1452 Happy 2004 求2004^n的所有因子和 积性函数应用的相关文章

HDU 1452 Happy 2004(因子和的积性函数)

题目链接 题意 : 给你一个X,让你求出2004的X次方的所有因子之和,然后对29取余. 思路 : 原来这就是积性函数,点这里这里这里,这里讲得很详细. 在非数论的领域,积性函数指所有对于任何a,b都有性质f(ab)=f(a)f(b)的函数. 在数论中的积性函数:对于正整数n的一个算术函数 f(n),若f(1)=1,且当a,b互质时f(ab)=f(a)f(b),在数论上就称它为积性函数. 若对于某积性函数 f(n),就算a, b不互质,也有f(ab)=f(a)f(b),则称它为完全积性的. s(

HDU 1452 FZU 1053 Happy 2004(逆元函数+因子和函数+大指数取模化简公式)

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

[HDOJ1492]Happy 2004(数论,快速幂,逆元,积性函数)

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1452 题意:求2004^n的所有因子和. 1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <climits> 6 #include <complex> 7 #include <

HDU 4002 Find the maximum (欧拉函数-积性函数的性质(2011年大连赛区网络赛第二题)

[题目链接]:click here~~ [题目大意]: 给出一个整数n,求一个数x,x在1到n之间,并且x/φ(x)最大(其中φ(x)为x的欧拉函数). [思路]: 由欧拉函数为积性函数,即:如果 则有: 且: 则有: 要使f(x)最大,须使x含尽量多的不同素数因子. 代码: /* * Problem: HDU No.4002 * Running time: 1700MS * Complier: java * Author: javaherongwei * Create Time: 0:08 2

积性函数,线性筛入门 HDU - 2879

HDU - 2879HeHe 题意:He[N]为[0,N−1]范围内有多少个数满足式子x2≡x (mod N),求HeHe[N]=He[1]×……×He[N] 我是通过打表发现的he[x]=2k,k为x是质因子个数,不过这是可以通过积性函数证明的. 关于积性函数的定义: 对于正整数n的一个算术函数 f(n),若f(1)=1,且当a,b互质时,f(ab)=f(a)f(b),在数论上就称它为积性函数.若对于某积性函数 f(n) ,就算a, b不互质,也有f(ab)=f(a)f(b),则称它为完全积性

HDU 6390 GuGuFishtion(莫比乌斯反演 + 欧拉函数性质 + 积性函数)题解

题意: 给定\(n,m,p\),求 \[ \sum_{a=1}^n\sum_{b=1}^m\frac{\varphi(ab)}{\varphi(a)\varphi(b)}\mod p \] 思路: 由欧拉函数性质可得:\(x,y\)互质则\(\varphi(xy)=\varphi(x)\varphi(y)\):\(p\)是质数则\(\varphi(p^a)=(p-1)^{a-1}\).因此,由上述两条性质,我们可以吧\(a,b\)质因数分解得到 \[ \begin{aligned} \sum_{

HDU 1452 Happy 2004

题目意思:求2004^x的所有正因数的和对29求余 解析: 我们用s(x)表示x的因子和: 2的因子为1,2,s(2)=3; 3的因子为1,3,s(3)=4; 6的因子为1,2,3,6,s(6)=12; 可以发现:s(6)=s(2)*s(3)=3*4=12; 4的因子为1,2,4,,s(4)=7; 5的因子为1,5,s(5)=6; 20的因子为1,2,4,5,10,20,s(20)=42: 可以发现:s(20)=s(4)*s(5)=7*6=42; s(25)=1+5+25=31 再看s(50)=

HDU 1452 Happy 2004 数论

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1452 题目描述: 让你求2004^x的所有因数之和, 模29 解题思路: 先将2014质因数分解, 2^2 * 3 * 167, 所以所有因数的个数就是(2x+1)*(x+1)*(x+1) , 我们列出公式, 相当于一个空间直角坐标系, 我们先将x, y平面上的点相加, 再加z轴上的, 最后得出公式 ans = (3^(x+1)-1) * (167^(x+1)-1)*(2^(2*x+1)-1)/3

hdu 1452 Happy 2004 膜拜这推导过程

Happy 2004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 920    Accepted Submission(s): 648 Problem Description Consider a positive integer X,and let S be the sum of all positive integer divis