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)\) 的数论函数. 完全积性函数指的是在任何情况下, ...
随机推荐
- PHP资源列表
一个PHP资源列表,内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具.Web 工具.书籍.电子书.经典博文等等. 初始翻译信息来自:<推荐!国外程序员整理的 PHP 资源大全& ...
- C语言之预处理
这是2016年的最后一篇博客,年初定的计划是写12篇博客,每月一篇,1/3转载,2/3原创,看来是实现不了了! -- 题外话.今天要写的东西是C语言中的预处理器,我们常说的宏定义的用法.为什么要写这个 ...
- python3爬取1024图片
这两年python特别火,火到博客园现在也是隔三差五的出现一些python的文章.各种开源软件.各种爬虫算法纷纷开路,作为互联网行业的IT狗自然看的我也是心痒痒,于是趁着这个雾霾横行的周末瞅了两眼,作 ...
- c#编程基础之字符串函数
c#常用的字符串函数 例一: 获取字符串的大小写函数 ToLower():得到字符串的小写形式 ToUpper():得到字符串的大写形式 注意: 字符串时不可变的,所以这些函数都不会直接改变字符串的内 ...
- ASP.NET Core 中文文档 第三章 原理(17)为你的服务器选择合适版本的.NET框架
原文:Choosing the Right .NET For You on the Server 作者:Daniel Roth 翻译:王健 校对:谢炀(Kiler).何镇汐.许登洋(Seay).孟帅洋 ...
- .NET Core之Entity Framework Core 你如何创建 DbContext
本文版权归博客园和作者吴双共同所有,欢迎转载,转载和爬虫请注明博客园蜗牛原文地址 http://www.cnblogs.com/tdws/p/5874212.html. 目前国内各大论坛,各位大牛的分 ...
- visual studio 编辑窗口 设置固定选项卡 使窗口选项卡多行显示
工具>选项> 确定后 如图就可以多行显示了.
- java多线程同步,等待,唤醒
notify().notifyAll().wait()属于java.lang.Object,java.lang.Thread也是Object,自然也有上述方法: sleep().interrupt() ...
- PostCSS一种更优雅、更简单的书写CSS方式
Sass团队创建了Compass大大提升CSSer的工作效率,你无需考虑各种浏览器前缀兼,只需要按官方文档的书写方式去写,会得到加上浏览器前缀的代码,如下: .row { @include displ ...
- navigationController 去掉背景图片、去掉底部线条
//去掉背景图片 [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMe ...