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 . 然后 ...
随机推荐
- 搭建网站 discuzx ecshop php
1.http://www.comsenz.com/downloads/install/discuzx下载
- JVM基础学习
public class TestJVM { // 运行时数据区[方法区.堆.程序计数器.虚拟机栈.本地方法栈] private static int _1M = 1024 * 1024; publi ...
- Orcle数据库查询练习复习:二
一.题目 1.找出所有成绩均低于80的学生姓名 select sname from student where sid in( ) select sname from student where si ...
- shell编程基础(2)---&&与||
shell 编程重要的应用就是管理系统,对于管理系统中成千上万的程序而言,查询某个文件名是否存在,并且获取该文件名所指代文件基本信息是系统管理员的基本任务.shell命令可以很轻松的完成这项任务. # ...
- (转)Struts 拦截器
一.拦截器是怎么实现: 实际上它是用Java中的动态代理来实现的 二.拦截器在Struts2中的应用 对于Struts2框架而言,正是大量的内置拦截器完成了大部分操作.像params拦截器将http请 ...
- Servlet的应用
1.重定向 HttpServletRequest接口提供的sendRedirect()方法用于生产302响应码和Location响应头,从而通知客户端去重新访问Location响应头中指定的U ...
- iptables配置——NAT地址转换
iptables nat 原理同filter表一样,nat表也有三条缺省的"链"(chains): PREROUTING:目的DNAT规则 把从外来的访问重定向到其他的机子上,比如 ...
- C# 对象与JSON串互相转换
using System;using System.IO;using System.Text;using Newtonsoft.Json; namespace OfflineAcceptControl ...
- [POJ1753]Flip Game(开关问题,枚举)
题目链接:http://poj.org/problem?id=1753 和上一个题一样,将初始状态存成01矩阵,就可以用位运算优化了.黑色白色各来一遍 /* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏ ...
- ie6调试工具Debugbar
http://www.my-debugbar.com/wiki/Doc/DebugbarInstall