本文共 978 字,大约阅读时间需要 3 分钟。
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
11 1 1 1
Sample Output
0
公式:
**gac(a^m−b^m,a^n−b^n)=a^gcd(m,n)−b^gcd(m,n)**
gcd(a^m−1,a^n−1)=a^gcd(m,n)−1
#include#include #include using namespace std;typedef long long LL;//const int N=10005;LL gcd(LL m,LL n){ if(n==0) return m; else return gcd(n,m%n);}LL qmi(LL m,LL k,LL p){ LL res=1%p,t=m; while(k) { if(k&1) res=res*t%p; t=t*t%p; k>>=1; } return res;}int main(){ ios::sync_with_stdio(false); int t; LL a,m,n,k; cin>>t; while(t--) { cin>>a>>m>>n>>k; LL sum=qmi(a,gcd(m,n),k)+k-1;//防止出现负数 cout< <
转载地址:http://xpyzi.baihongyu.com/