题意

给出\(x\),求\(2004^x\)的所有因子和

分析

\(2004=2*2*3*167\)

则\(2004^x\)=\(2^{2x}*3^x*167^x\)

s[\(2004^x\)]=s[\(2^{2x}\)]s[\(3^x\)]s[\(167^x\)]

s[i]为积性函数

如果\(p\)为素数,则$s(p^x) = (1 + p^1 + p^2 + ... p^x) = (p^{x+1} - 1) / (p-1) $

然后求出2,3,167的逆元即可

注意开long long

代码

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
using namespace std; #define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(b))
#pragma comment(linker, "/STACK:102400000,102400000")
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}} int a[4]={0,2,3,22},x;
const int mod=29;
ll work(int p,int x)
{
ll ret=1;
for(;x;x>>=1,(p*=p)%=mod) if(x&1) (ret*=p)%=mod;
return ret;
} int main()
{
while(scanf("%d",&x),x)
{
ll ans=1;ans=ans*(work(a[1],2*x+1)-1)%mod;
F(i,2,3)
ans=ans*((work(a[i]%mod,x+1)-1)*work((a[i]-1)%mod,mod-2))%mod;
printf("%lld\n",ans);
}
return 0;
}

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

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

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

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

    题目链接 题意 : 给你一个X,让你求出2004的X次方的所有因子之和,然后对29取余. 思路 : 原来这就是积性函数,点这里这里这里,这里讲得很详细. 在非数论的领域,积性函数指所有对于任何a,b都 ...

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

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

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

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

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

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

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

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

  7. 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的因子.为什么呢?原因 ...

  8. Divisor counting [线性筛积性函数]

    Divisor counting 题目大意:定义f(n)表示整数n的约数个数.给出正整数n,求f(1)+f(2)+...+f(n)的值. 注释:1<=n<=1000,000 想法:我们再次 ...

  9. [模板] 积性函数 && 线性筛

    积性函数 数论函数指的是定义在正整数集上的实或复函数. 积性函数指的是当 \((a,b)=1\) 时, 满足 \(f(a*b)=f(a)*f(b)\) 的数论函数. 完全积性函数指的是在任何情况下, ...

随机推荐

  1. SGU 106 The equation【扩展欧几里得】

    先放一张搞笑图.. 我一直wa2,这位不认识的大神一直wa9...这样搞笑的局面持续了一个晚上...最后各wa了10发才A... 题目链接: http://acm.hust.edu.cn/vjudge ...

  2. Drainage Ditches--hdu1532(网络流 模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/Other ...

  3. 安装使用Spring boot 写一个hello1

    一.创建springboot 项目 二.进行代编写 1.连接数据库:application.properties里配置 spring.datasource.driverClassName=com.my ...

  4. Vue基础学习

    使用vue-cli构建初始化vue项目 vue init webpack myfirst 项目截图:(开发工具:webStorm) 主要练习了vue的基本指令:v-bind.v-if.v-show.v ...

  5. 【APUE】一个fork的面试题及字符设备、块设备的区别

    具体内容见:http://coolshell.cn/articles/7965.html 字符设备.块设备主要区别是:在对字符设备发出读/写请求时,实际的硬件I/O一般就紧接着发生了,而块设备则不然, ...

  6. [Angular] Expose Angular Component Logic Using State Reducers

    A component author has no way of knowing which state changes a consumer will want to override, but s ...

  7. 我所写的CNN框架 VS caffe

    我所写的CNN框架 VS caffe 一个月前.自己模仿caffe实现了一个卷积神经网络的框架. 同样点 1无缝支持CPU和GPU模式,GPU模式使用cuda实现. 不同点 1我的CNN不依赖与不论什 ...

  8. 【转】TestNG中的并发(多线程)

    优势 并行(多线程)技术在软件术语里被定义为软件.操作系统或者程序可以并行地执行另外一段程序中多个部分或者子组件的能力 多线程方式拥有很大的优势: 1). 减少测试运行时间 如果测试集里包含了大量的用 ...

  9. Node 即学即用 笔记 思维导图

    Node即学即用   REPL(Read-Evaluate-Print-Loop)     console.log     .clear .help .exit     require('http') ...

  10. 基于开源项目的在线网络视频直播项目---pc端的推流

    https://github.com/winlinvip/simple-rtmp-server/issues/66 https://github.com/justinmakaila/iOS-Frame ...