题目链接:

PowMod

Time Limit: 3000/1500 MS (Java/Others)  

  Memory Limit: 262144/262144 K (Java/Others)

Problem Description
Declare:
k=∑mi=1φ(i∗n) mod 1000000007

n is a square-free number.

φ is the Euler's totient function.

find:
ans=kkkk...k mod p

There are infinite number of k

 
Input
 
Multiple test cases(test cases ≤100), one line per case.

Each line contains three integers, n,m and p.

1≤n,m,p≤10^7

 
Output
 
For each case, output a single line with one integer, ans.
 
Sample Input
 
1 2 6
1 100 9
 
Sample Output
 
4
7
 
题意:
 
先算出那个k的值,再根据指数循环节算出答案;
 
思路:
 
这个博客给出了具体的推导过程,我就是参考这个的,而且代码也是;
 
AC代码;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e7+10;
const int maxn=500+10;
const double eps=1e-8; int phi[N],vis[N],prime[N],cnt;
LL sum[N],a[100];
inline void Init()
{
cnt=0;
sum[1]=1;
phi[1]=1;
For(i,2,N-1)
{
if(!vis[i])
{
for(int j=2*i;j<N;j+=i)
{
if(!vis[j])phi[j]=j;
vis[j]=1;
phi[j]=phi[j]/i*(i-1);
}
phi[i]=i-1;
prime[++cnt]=i;
}
sum[i]=(sum[i-1]+phi[i])%mod;
}
} LL pow_mod(LL x,LL y,LL mo)
{
LL s=1,base=x;
while(y)
{
if(y&1)s=s*base%mo;
base=base*base%mo;
y>>=1;
}
return s;
} LL work(LL a,LL b)
{
if(b==1)return 0;
LL sum=work(a,phi[b]);
sum=sum+phi[b];
LL ans=pow_mod(a,sum,b);
return ans;
} LL dfs(int pos,LL n,LL m)
{
if(n==1)return sum[m];
if(m==0)return 0;
return ((a[pos]-1)*dfs(pos-1,n/a[pos],m)%mod+dfs(pos,n,m/a[pos]))%mod;
} inline LL solve(LL n,LL m)
{
int num=0;
LL temp=n;
if(!vis[n])a[++num]=n;
else
{
for(int i=1;i<=cnt;i++)
{
if(n<prime[i])break;
if(n%prime[i]==0)
{
a[++num]=prime[i];
n/=prime[i];
}
}
}
return dfs(num,temp,m);
} int main()
{
Init();
LL n,m,p;
while(cin>>n>>m>>p)
{
LL k=solve(n,m);
LL ans=work(k,p);
print(ans);
} return 0;
}

  

hdu-5728 PowMod(数论)的更多相关文章

  1. HDU 5728 - PowMod

    HDU 5728 - PowMod 题意:    定义: k = ∑(i=1,m) φ(i∗n) mod 1000000007 给出: n,m,p ,且 n 无平方因子 求: ans= k^(k^(k ...

  2. HDU 5278 PowMod 数论公式推导

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

  3. HDU - 5728:PowMod (欧拉函数&指数循环节)

    Declare: k=∑ m i=1 φ(i∗n) mod 1000000007 k=∑i=1mφ(i∗n) mod 1000000007 n n is a square-free number. φ ...

  4. hdu GuGuFishtion 6390 数论 欧拉函数

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6390 直接开始证明: 我们设…………………………………….....…...............………… ...

  5. HDU 1299 基础数论 分解

    给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + ...

  6. HDU 5317 RGCDQ (数论素筛)

    RGCDQ Time Limit: 3000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status ...

  7. HDU 1495 非常可乐(数论,BFS)

    非常可乐 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  8. HDU 1722 Cake (数论 gcd)(Java版)

    Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1722 ——每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2 . 然后 ...

  9. L - LCM Walk HDU - 5584 (数论)

    题目链接: L - LCM Walk HDU - 5584 题目大意:首先是T组测试样例,然后给你x和y,这个指的是终点.然后问你有多少个起点能走到这个x和y.每一次走的规则是(m1,m2)到(m1+ ...

  10. hdu 5525 Product 数论算贡献

    Product Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Proble ...

随机推荐

  1. DLL注入新姿势:反射式DLL注入研究

    在分析koadic渗透利器时,发现它有一个注入模块,其DLL注入实现方式和一般的注入方式不一样.搜索了一下发现是由HarmanySecurity的Stephen Fewer提出的ReflectiveD ...

  2. poj 2932 Coneology (扫描线)

    题意 平面上有N个两两不相交的圆,求全部最外层的,即不被其它圆包括的圆的个数并输出 思路 挑战程序竞赛P259页 代码 /* ************************************* ...

  3. [Algorithm] Write a Depth First Search Algorithm for Graphs in JavaScript

    Depth first search is a graph search algorithm that starts at one node and uses recursion to travel ...

  4. 面试之SQL(1)--选出选课数量&gt;=2的学号

    ID      Course 1 AA 1 BB 2 AA 2 BB 2 CC 3 AA 3 BB 3 CC 3 DD 4 AA NULL NULL 选出选课数量>=2的学号 select di ...

  5. bootstrap到底是用来做什么的(概念)

    Bootstrap官网:http://v3.bootcss.com/ Bootstrap是Twitter推出的一个用于前端开发的开源工具包.它由Twitter的设计师Mark Otto和Jacob T ...

  6. iframe截取站点的部分内容

    <div style="width:630px;height:350px;overflow:hidden;border:0px">                  & ...

  7. grep man 有删减 百科

    NAME grep, egrep, fgrep, rgrep - print lines matching a pattern SYNOPSIS grep [OPTIONS] PATTERN [FIL ...

  8. 编程算法 - 多重部分和问题 代码(C)

    多重部分和问题 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 有n种不同大小的数字a, 每种各m个. 推断能否够从这些数字之中选出若干使它们的 ...

  9. Quartz 2D编程指南(2)图形上下文(Graphics Contexts)

    Graphics Contexts       一个Graphics Context表示一个绘制目标(也能够理解为图形上下文).它包括绘制系统用于完毕绘制指令的绘制參数和设备相关信息.Graphics ...

  10. undefined reference to libiconv_open ext/iconv/.libs/iconv.o by install phpsource

    错误信息:ext/iconv/.libs/iconv.o(.text+0x30e2): In function `php_iconv_stream_filter_factory_create':/ho ...