FZU 1759 Super A^B mod C 指数循环节
2016-07-20 11:20
411 查看
Problem 1759 Super A^B mod C
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000).
There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a single space.
For each testcase, output an integer, denotes the result of A^B mod C.
3 2 4 2 10 1000
1 24
思路:指数循环节,数据水,并没有B<C&&A,C不互质的;
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000).
Input
There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a single space.
Output
For each testcase, output an integer, denotes the result of A^B mod C.
Sample Input
3 2 4 2 10 1000
Sample Output
1 24思路:指数循环节,数据水,并没有B<C&&A,C不互质的;
#include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define ll __int64 #define esp 0.00000000001 const int N=1e5+10,M=1e6+10,inf=1e9+10; const int mod=1000000007; #define MAXN 10000010 ll quickpow(ll x,ll y,ll z) { ll ans=1; while(y) { if(y&1) ans*=x,ans%=z; x*=x; x%=z; y>>=1; } return ans; } ll phi(ll n) { ll i,rea=n; for(i=2;i*i<=n;i++) { if(n%i==0) { rea=rea-rea/i; while(n%i==0) n/=i; } } if(n>1) rea=rea-rea/n; return rea; } char a[M]; int main() { ll x,y,z,i,t; while(~scanf("%I64d%s%I64d",&x,a,&z)) { t=strlen(a); ll p=phi(z); ll ans=0; for(i=0;i<t;i++) ans=(ans*10+a[i]-'0')%p; ans+=p; printf("%I64d\n",quickpow(x,ans,z)); } return 0; }
相关文章推荐
- jira操作
- Android布局中实现圆角边框
- eclipse结合git和github
- Gi之(二)Git基础命令
- mysql 父类子类查询
- 设置input上传类型
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2 670D 【二分答案】
- top 内存字段解析
- [置顶] 多GPU运行Deep Learning 和 并行Deep Learning(待续)
- SystemUI下拉通知栏的源码分析
- 装饰模式(Decorator)
- Redis客户端开发包:Jedis学习-高级应用
- Java的native关键字以及JNI
- 嵌入式系统 Boot Loader 技术内幕【转】
- HttpRequestDeviceUtils
- mr的logs的查看
- 【phantomjs】使用phantomjs生成highChart的图片(待完善)
- 2016 Multi-University Training Contest 1 1001 Abandoned country (最小生成树+DFS)
- 模板使用入门示例
- urllib模块