hdu-5728 PowMod(数论)
2016-07-25 11:39
375 查看
题目链接:
Memory Limit: 262144/262144 K (Java/Others)
[align=left]Problem Description[/align]
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
[align=left]Input[/align]
[align=left] [/align]
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
[align=left]Output[/align]
[align=left] [/align]
For each case, output a single line with one integer, ans.
[align=left]Sample Input[/align]
[align=left] [/align]
1 2 6
1 100 9
[align=left]Sample Output[/align]
[align=left] [/align]
4
7
题意:
先算出那个k的值,再根据指数循环节算出答案;
思路:
这个博客给出了具体的推导过程,我就是参考这个的,而且代码也是;
传送门
AC代码;
PowMod
Time Limit: 3000/1500 MS (Java/Others)Memory Limit: 262144/262144 K (Java/Others)
[align=left]Problem Description[/align]
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
[align=left]Input[/align]
[align=left] [/align]
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
[align=left]Output[/align]
[align=left] [/align]
For each case, output a single line with one integer, ans.
[align=left]Sample Input[/align]
[align=left] [/align]
1 2 6
1 100 9
[align=left]Sample Output[/align]
[align=left] [/align]
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 ,vis ,prime ,cnt; LL sum ,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 )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; }
相关文章推荐
- 根据年龄分割查询每个年龄段的人数
- word2vec
- open系统调用
- Could not connect to SMTP host,PKIX path building failed,unable to find valid certification path...
- strstr函数与翻转字符串
- Android Studio 主题、字体大小的设置
- c语言==复合数据类型(14)
- 奶牛的锻炼
- 嗖嗖嗖
- Genymotion的使用以及错误解决
- web前端开发小工具集合
- Linux查看CPU和内存使用情况【转】
- luigi学习1
- poj 2965---The Pilots Brothers' refrigerator
- PAT 1018 A+B in Hogwarts (20)
- JavaScript跨域总结与解决办法
- iOS errorcode为-1011 问题及解答
- Bundler的安装和配置
- 重磅!8大策略让你对抗机器学习数据集里的不均衡数据
- redis和memcache