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 . 然后 ...
随机推荐
- C Primer Plus之C预处理器和C库
编译程序前,先由预处理器检查程序(因此称为预处理器).根据程序中使用的预处理器指令,预处理器用符号缩略语所代表的内容替换程序中的缩略语. 预处理器不能理解C,它一般是接受一些文件并将其转换成其他文本. ...
- Cache 应用程序数据缓存
System.Web.Caching 命名空间提供用于缓存服务器上常用数据的类.此命名空间包括 Cache 类,该类是一个字典,您可以在其中存储任意数据对象,如哈希表和数据集.它还为这些对象提供了失效 ...
- 解决NTFS分区上的代码在linux上编译后没有权限执行
win7下的cpp代码,在ubuntu下编译后,可执行文件不能执行,root也不行. 将代码拷贝到ubuntu上,再编译生成的可执行文件则可以执行.或者将win7分区上的可执行文件拷贝出来,然后chm ...
- lintcode :Reverse Words in a String 翻转字符串
题目: 翻转字符串 给定一个字符串,逐个翻转字符串中的每个单词. 样例 给出s = "the sky is blue",返回"blue is sky the" ...
- lintcode:Minimum Subarray 最小子数组
题目: 最小子数组 给定一个整数数组,找到一个具有最小和的子数组.返回其最小和. 样例 给出数组[1, -1, -2, 1],返回 -3 注意 子数组最少包含一个数字 解题: 和最大子数组 ,差不多的 ...
- Minimum_Window_Substring两种方法求解
题目描述: Given a string S and a string T, find the minimum window in S which will contain all the chara ...
- Python中itertools模块
itertools模块包含创建有效迭代器的函数,可以用各种方式对数据进行循环操作,此模块中的所有函数返回的迭代器都可以与for循环语句以及其他包含迭代器(如生成器和生成器表达式)的函数联合使用. ch ...
- 40. Combination Sum II
题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combination ...
- OpenVAS漏洞扫描基础教程之OpenVAS概述及安装及配置OpenVAS服务
OpenVAS漏洞扫描基础教程之OpenVAS概述及安装及配置OpenVAS服务 1. OpenVAS基础知识 OpenVAS(Open Vulnerability Assessment Sys ...
- sql中exists,not exists的用法
exists : 强调的是是否返回结果集,不要求知道返回什么, 比如: select name from student where sex = 'm' and mark exists(select ...