题目链接

题意 : 给你一个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(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)

再看本题 :

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

2004=2^2 *3 *167

2004^X=4^X * 3^X *167^X

s(2004^X) ) = (s(2^2X))) * (s(3^X))) * (s(167^X))) 而 167%29=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) 除法的

s(2004^X)=(2^(2X+1)-1)* (3^(X+1)-1)/2  *(22^(X+1)-1)/21

(a*b)/c %M= a%M* b%M  * inv(c)

c*inv(c)=1 %M    模为1的所有数  inv(c)为最小可以被c整除的

inv(2)=15,  inv(21)=18    2*15=1 mod 29, 18*21=1 mod 29

s(2004^X)=((2^(2X+1)-1)* (3^(X+1)-1)/2  *(22^(X+1)-1)/21)mod 29  =((2^(2X+1)-1)* (3^(X+1)-1)*15 *(22^(X+1)-1)*18)mod29

b^(-1)是 b的逆元素(%p)即上面的inv

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 <math.h>
#include <iostream> using namespace std ; int multimod(int a,int n)//乘方模
{
int res = ;
while(n)
{
if(n & )
{
res *= a ;
res %= ;
}
a *= a ;
a %= ;
n >>= ;
}
return res ;
}
int main()
{
int x ;
while(~scanf("%d",&x))
{
if(x == ) break ;
int a = (multimod(,*x+)-) ;
int b = (multimod(,x+)-)* ;
int c = (multimod(,x+)-)* ;
printf("%d\n",(a*b*c)%) ;
}
return ;
}

HDU 1452 Happy 2004(因子和的积性函数)的更多相关文章

  1. HDU 1452 Happy 2004 (逆元+快速幂+积性函数)

    G - Happy 2004 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Subm ...

  2. hdu1452 Happy 2004(规律+因子和+积性函数)

    Happy 2004 题意:s为2004^x的因子和,求s%29.     (题于文末) 知识点: 素因子分解:n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en 因子 ...

  3. 数学--数论--Hdu 1452 Happy 2004(积性函数性质+和函数公式+快速模幂+乘法逆元)

    Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your ...

  4. HDU 1452 Happy 2004(因数和+费马小定理+积性函数)

    Happy 2004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  5. 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 ...

  6. Hdu 1452 Happy 2004(除数和函数,快速幂乘(模),乘法逆元)

    Problem Description Considera positive integer X,and let S be the sum of all positive integer diviso ...

  7. HDU1452Happy 2004(高次幂取模+积性函数+逆元)

    题目意思:2004^x的所有正因数的和(S)对29求余:输出结果: 原题链接 题目解析:解析参照来源:点击打开链接 因子和 6的因子是1,2,3,6; 6的因子和是s(6)=1+2+3+6=12; 2 ...

  8. HDU1452:Happy 2004(积性函数)(因子和)

    题意 给出\(x\),求\(2004^x\)的所有因子和 分析 \(2004=2*2*3*167\) 则\(2004^x\)=\(2^{2x}*3^x*167^x\) s[\(2004^x\)]=s[ ...

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

    HDU - 2879HeHe 题意:He[N]为[0,N−1]范围内有多少个数满足式子x2≡x (mod N),求HeHe[N]=He[1]×……×He[N] 我是通过打表发现的he[x]=2k,k为 ...

随机推荐

  1. Linux实现的IEEE 802.q VLAN

    本文转载自: http://blog.chinaunix.net/uid-20786208-id-4291059.html Technorati 标签: Linux VLAN   ---------- ...

  2. 【风马一族_代码英语】代码英语之八 ADB

    adb wireless   无线调试  adb ---------------------------- preferences 首选项 ---------------------------- a ...

  3. “==”,比较的是引用 “equals方法”比较的是具体内容

    package com.java1234.chap03.sec08; public class Demo2 { public static void main(String[] args) { //“ ...

  4. 转:Android studio Gradle

    提高Android Studio中Gradle执行效率 分类: android studio2015-06-26 11:54 2374人阅读 评论(2) 收藏 举报 android studiogra ...

  5. VS2005 VS2008编译的程序在Win7下以管理员身份运行的设置

    在VS2005或者VS2008 里面,直接项目右键---属性---连接器---清单文件---uac执行级别   选择requireAdministrator  重新编译 这样你的程序直接运行就拥有管理 ...

  6. Java操作MongoDB

    上一篇文章: http://www.cnblogs.com/hoojo/archive/2011/06/01/2066426.html 介绍到了在MongoDB的控制台完成MongoDB的数据操作,通 ...

  7. css透明(支持各浏览器)

    opacity: 0.4;filter: progid:DXImageTransform.Microsoft.Alpha(opacity=40); -ms-filter: "progid:D ...

  8. Spark菜鸟学习营Day1 从Java到RDD编程

    Spark菜鸟学习营Day1 从Java到RDD编程 菜鸟训练营主要的目标是帮助大家从零开始,初步掌握Spark程序的开发. Spark的编程模型是一步一步发展过来的,今天主要带大家走一下这段路,让我 ...

  9. 1014. Waiting in Line (30)

    Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...

  10. FastLoad错误 — SELECT Failed. 2652

    SELECT * FROM   teradata_education. emp_fl;     在做查询时碰到2652错误.   SELECT Failed. 2652: Operation not ...