hdu2685gcd性质
来源:互联网 发布:php class exists 500 编辑:程序博客网 时间:2024/04/29 04:25
Problem Description
To think of a beautiful problem description is so hard for me that let’s just drop them off. :)
Given four integers a,m,n,k,and S = gcd(a^m-1,a^n-1)%k,calculate the S.
Input
The first line contain a t,then t cases followed.
Each case contain four integers a,m,n,k(1<=a,m,n,k<=10000).
Output
One line with a integer S.
Sample Input
1
1 1 1 1
Sample Output
0
gcd(a^m-b^m, a^n-b^n) = a^gcd(m,n)-b^gcd(m,n);
这里b=1;
#include <iostream>using namespace std;typedef long long LL;LL gcd(LL a,LL b){ if(!b) return a; return gcd(b,a%b);}LL power(LL a,LL b,LL mod){ LL ans=1; while(b) { if(b&1) { ans=(ans*a)%mod; b--; } else { b>>=1; a=(a*a)%mod; } } return ans;}int main(){int t; LL a,m,n,k; cin>>t; while(t--) { cin>>a>>m>>n>>k; cout<<(power(a,gcd(m,n),k)+k-1)%k<<endl; } return 0;}
0 0
- hdu2685gcd性质
- 博客性质
- 三角形性质
- MST性质
- 关系性质
- 整数性质
- 计算性质
- 热学性质
- 字符串性质
- 整数性质
- PCM性质
- flash性质
- HDD性质
- 整数性质
- 文字性质的CSS
- c++的重要性质
- 多叉树的性质
- sinc函数的性质
- POJ 1679 The Unique MST (次小生成树)
- 创建并已入javaweb项目,运行之后提示如下错误
- std::vector的几种遍历方式比较
- 通知的具体使用——通知的发送、接受、通知的移除
- malloc和new的区别
- hdu2685gcd性质
- Struts2环境的搭建
- 有关内存的思考?GetMemory()
- UC/OS II 软件定时器
- ThinkPHP-数据库配置和模板调用
- Java 垃圾回收机制 GC的算法和操作
- MySQL学习之路二
- Java8揭秘(三)Default 方法
- Linux环境变量的设置和查看方法 http://soft.chinabyte.com/os/169/11412169.shtml