HDU 5278 PowMod 数论公式推导
题意:中文题自己看吧
分析:这题分两步
第一步:利用已知公式求出k;
第二步:求出k然后使用欧拉降幂公式即可,欧拉降幂公式不需要互质(第二步就是BZOJ3884原题了)
求k的话就需要构造了(引入官方题解)

然后就求出k了,我就很奇怪为什么是这个式子,然后就网上搜啊搜
找到了一个推导(看完了以后恍然大悟)
推导链接:http://blog.csdn.net/wust_zzwh/article/details/51966450
高度仰慕数学好的巨巨
吐槽:这个题n是无平方因子,然后就要往欧拉函数是积性函数的性质上想,但是主要是还是要多做数学题
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int N = 1e7+;
const int mod=1e9+;
bool check[N];
LL phi[N],prime[N>>],tot;
LL sum[N],k,n,m,p;
LL qpow(LL a,LL b,LL mod){
LL ret=;
while(b){
if(b&)ret=(ret*a)%mod;
a=(a*a)%mod;
b>>=;
}
return ret;
}
void getphi(){
phi[]=;tot=;
for(int i=;i<=N-;++i){
if(!check[i]){
prime[++tot]=i;
phi[i]=i-;
}
for(int j=;j<=tot;++j){
if(i*prime[j]>N-)break;
check[i*prime[j]]=true;
if(i%prime[j]==){
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
else phi[i*prime[j]]=phi[i]*(prime[j]-);
}
}
for(int i=;i<=N-;++i){
sum[i]=(sum[i-]+phi[i])%mod;
}
}
LL solve(LL n,LL m){
if(m==)return ;
if(m==)return phi[n];
if(n==)return sum[m];
if(phi[n]==n-){
return (phi[n]*solve(,m)%mod+solve(n,m/n))%mod;
}
for(int i=;i<=tot&&prime[i]*prime[i]<=n;++i){
if(n%prime[i])continue;
return (phi[prime[i]]*solve(n/prime[i],m)%mod+solve(n,m/prime[i]))%mod;
}
}
LL f(LL x){
if(x==)return ;
return qpow(k,f(phi[x])+phi[x],x);
}
int main(){
getphi();
while(~scanf("%I64d%I64d%I64d",&n,&m,&p)){
k=solve(n,m);
printf("%I64d\n",f(p));
}
return ;
}
HDU 5278 PowMod 数论公式推导的更多相关文章
- HDU 5728 - PowMod
HDU 5728 - PowMod 题意: 定义: k = ∑(i=1,m) φ(i∗n) mod 1000000007 给出: n,m,p ,且 n 无平方因子 求: ans= k^(k^(k ...
- 2015多校第8场 HDU 5382 GCD?LCM! 数论公式推导
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5382 题意:函数lcm(a,b):求两整数a,b的最小公倍数:函数gcd(a,b):求两整数a,b的最 ...
- 数学--数论--HDU 2802 F(N) 公式推导或矩阵快速幂
Giving the N, can you tell me the answer of F(N)? Input Each test case contains a single integer N(1 ...
- hdu GuGuFishtion 6390 数论 欧拉函数
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6390 直接开始证明: 我们设…………………………………….....…...............………… ...
- HDU 1299 基础数论 分解
给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + ...
- HDU 5317 RGCDQ (数论素筛)
RGCDQ Time Limit: 3000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit Status ...
- hdu 5278 Geometric Progression 高精度
Geometric Progression Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contes ...
- HDU 1495 非常可乐(数论,BFS)
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDU 1722 Cake (数论 gcd)(Java版)
Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1722 ——每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2 . 然后 ...
随机推荐
- [转]数据结构之Trie树
1. 概述 Trie树,又称字典树,单词查找树或者前缀树,是一种用于快速检索的多叉树结构,如英文字母的字典树是一个26叉树,数字的字典树是一个10叉树. Trie一词来自retrieve,发音为/tr ...
- Android中使用HTTP和HttpClient进行通信
/** * 使用HTTP的Get方式进行数据请求 */ protected void httpGet() { /** * 进行异步请求 */ new AsyncTask<String, Void ...
- SpringAOP拦截Controller,Service实现日志管理(自定义注解的方式)
转载:http://itindex.net/detail/50710-springaop-controller-service 从业近二,三年了,第一次写博客,平时做做脚手架或者架构一些基础框架然后给 ...
- Hibernate逍遥游记-第13章 映射实体关联关系-005双向多对多(使用组件类集合\<composite-element>\)
1. <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hi ...
- Qt网络通信骨架解析,QtClient QtServer QtSerialPort
http://blog.csdn.net/Dr_Abel/article/details/52469134#t18
- 前端自动化工具:Grunt使用教程
1.下载node.js,然后将node.exe文件所在的目录加入path环境变量 2.安装npm管理工具 2.1.下载npm源码,解压到npm文件夹里,不要把npm放在和node.exe相同的文件夹 ...
- 人脸识别必读的N篇文章
一,人脸检测/跟踪 人脸检测/跟踪的目的是在图像/视频中找到各个人脸所在的位置和大小:对于跟踪而言,还需要确定帧间不同人脸间的对应关系. 1, Robust Real-time Object Dete ...
- API设计
---恢复内容开始--- 参考:http://www.cnblogs.com/youxin/p/3967274.html http://scotch.io/tutorials/simple-larav ...
- static,this,抽象类,接口和包
1. static 1)静态变量:Java虚拟机为静态变量开辟单独的存储空间,所以所有的对象内部的静态变量在内存中都指向同一个地址,那么不管哪个对象改变这个成员变量,所有对象中该成员变量的值都发生变化 ...
- SQLiteParameter不能将TableName作为参数
http://stackoverflow.com/questions/1274432/sqlite-parameters-not-allowing-tablename-as-parameter Gen ...