hdu1452 Happy 2004(规律+因子和+积性函数)
题意:s为2004^x的因子和,求s%29. (题于文末)
知识点:
素因子分解:n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en
因子和: Sum=(p1^0+p1^1….p1^e1)*(p2^0+p2^1…p2^e2)……(pn^0+…pn^en)
=
;
积性函数:s(xy)=s(x)*s(y) (比如:幂函数,因子和,欧拉函数,莫比乌斯函数)
对于正整数n的一个算术函数 f(n),若f(1)=1,且当a,b互质时f(ab)=f(a)f(b),在数论上就称它为积性函数。
若对于某积性函数 f(n),就算a, b不互质,也有f(ab)=f(a)f(b),则称它为完全积性的。
%运算:
% k =
=
为m模k的逆元
题解:
一般模值(mod)较小时会有规律,可以找下循环节。
发现答案的循环结为28.
#include<iostream>
using namespace std;
int a[]={6,16,8,10,25,7,14,3,23,17,13,17,0,27,7,14,15,17,26,26,20,17,9,22,22,23,0,1}; int main()
{
int x;
while(cin>>x&&x)
{
cout<<a[(x-1)%28]<<endl;
}
/*找规律过程
for(x=1;x<=100;x++)
{
int a2=1,a3=1,a167=1,ans2=0,ans3=0,ans167=0;
for(int i=0;i<=x*2;i++)
{
ans2+=a2;
a2*=2;
ans2%=29;
a2%=29;
}
for(int i=0;i<=x;i++)
{
ans3+=a3;
a3*=3;
ans3%=29;
a3%=29;
}
for(int i=0;i<=x;i++)
{
ans167+=a167;
a167*=167;
ans167%=29;
a167%=29;
}
cout<<ans2*ans3*ans167%29<<endl;
}*/
return 0;
}
再给出一般解:
因子和为积性函数,so sum(2004^X)= sum(2^2X) * sum(3^X)* sum(167^X)
sum(2004^X)%29=sum(2^2X) %29 * sum(3^X)%29 * sum(167^X)%29
=sum((2%29)^2X) %29 * sum((3%29)^X)%29 * sum((167%29)^X)%29
=sum(2^2X) * sum(3^X) * sum(22^X)%29
=
*
*
%29
2的逆元是15 ,21的逆元是18
=((2^(2X+1)-1)* (3^(X+1)-1)*15 *(22^(X+1)-1)*18)%29
快速幂取模,实现2^2x,3^x,22^x O(logn)的运算
#include <iostream>
#include <cstdio>
#include <cmath> using namespace std; int quick_mod( int a, int n )
{
int b = 1;
while( n > 1 )
if( n % 2 == 0 )
{
a = ( a * a ) % 29;
n /= 2;
}
else
{
b = b * a % 29;
n--;
}
return a * b % 29;
}
int main()
{
int X;
int a, b, c;
while( scanf("%d",&X), X )
{
a = quick_mod( 2, 2 * X + 1 );
b = quick_mod( 3, ( X + 1 ) );
c = quick_mod( 22, ( X + 1 ) );
printf("%d\n",( a - 1 ) * (( b - 1 ) * 15) * ( c - 1 ) * 18 % 29) ;
}
return 0;
}
全题:
Happy 2004
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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
hdu1452 Happy 2004(规律+因子和+积性函数)的更多相关文章
- 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都 ...
- HDU1452:Happy 2004(积性函数)(因子和)
题意 给出\(x\),求\(2004^x\)的所有因子和 分析 \(2004=2*2*3*167\) 则\(2004^x\)=\(2^{2x}*3^x*167^x\) s[\(2004^x\)]=s[ ...
- HDU1452Happy 2004(高次幂取模+积性函数+逆元)
题目意思:2004^x的所有正因数的和(S)对29求余:输出结果: 原题链接 题目解析:解析参照来源:点击打开链接 因子和 6的因子是1,2,3,6; 6的因子和是s(6)=1+2+3+6=12; 2 ...
- 数学--数论--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(因数和+费马小定理+积性函数)
Happy 2004 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- POJ 2480 Longge's problem (积性函数,欧拉函数)
题意:求∑gcd(i,n),1<=i<=n思路:f(n)=∑gcd(i,n),1<=i<=n可以知道,其实f(n)=sum(p*φ(n/p)),其中p是n的因子.为什么呢?原因 ...
- Divisor counting [线性筛积性函数]
Divisor counting 题目大意:定义f(n)表示整数n的约数个数.给出正整数n,求f(1)+f(2)+...+f(n)的值. 注释:1<=n<=1000,000 想法:我们再次 ...
- [模板] 积性函数 && 线性筛
积性函数 数论函数指的是定义在正整数集上的实或复函数. 积性函数指的是当 \((a,b)=1\) 时, 满足 \(f(a*b)=f(a)*f(b)\) 的数论函数. 完全积性函数指的是在任何情况下, ...
随机推荐
- 黄聪:C#类似Jquery的html解析类HtmlAgilityPack基础类介绍及运用
Html Agility Pack下载地址:http://htmlagilitypack.codeplex.com/ Html Agility Pack 源码中的类大概有28个左右,其实不算一个很复杂 ...
- Oracle数据加载之sqlldr工具的介绍
环境: 服务端:RHEL6.4 + Oracle 11.2.0.4 客户端:WIN10 + Oracle 11.2.0.1 client 目录: sqlldr语法 sqlldr实验准备 sqlldr常 ...
- 如果你也会C#,那不妨了解下F#(4):了解函数及常用函数
函数式编程其实就是按照数学上的函数运算思想来实现计算机上的运算.虽然我们不需要深入了解数学函数的知识,但应该清楚函数式编程的基础是来自于数学. 例如数学函数\(f(x) = x^2+x\),并没有指定 ...
- 【转】Asp.net MVC定义短网址
在MVC的逻辑代码里,Controller和Action是必须的,但是在网址里,并不需要完全体现Controller和Action.比如我们经常希望看到http://localhost/About而不 ...
- ASP.NET Core服务器综述
原文地址:Servers overview for ASP.NET Core By Tom Dykstra, Steve Smith, Stephen Halter, and Chris Ross A ...
- jquery获取dropdownlist的value和text值
1.jquery //获取value值 $("#ddlSubmodel").val(); //获取text值 $("#ddlSubmodel").find(&q ...
- Xcode7.1环境下上架iOS App到AppStore 流程① (Part 一)
前言部分 之前App要上架遇到些问题到网上搜上架教程发现都是一些老的版本的教程 ,目前iTunesConnect 都已经迭代好几个版本了和之前的 界面风格还是有很大的差别的,后面自己折腾了好久才终于把 ...
- C#开发微信门户及应用(33)--微信现金红包的封装及使用
我在上篇随笔<C#开发微信门户及应用(32)--微信支付接入和API封装使用>介绍为微信支付的API封装及使用,其中介绍了如何配置好支付环境,并对扫码支付的两种方式如何在C#开发中使用进行 ...
- ASP.NET用QQ,网易发送邮件以及添加附件
教程:ASP.NET用QQ,网易发送邮件以及添加附件 这是我用QQ邮箱出现的异常: 命令顺序不正确. 服务器响应为:Error: need EHLO and AUTH first !无法从传输连接中读 ...
- Yii 2.x Behavior - 类图
yii\base\Component 继承这个类的类都具备扩展行为的能力