标签:
题目链接:
#include <bits/stdc++.h> using namespace std; typedef long long LL; //const LL mod=1e9+7; const int N=1e5+6; int gcd(int x,int y) { if( y == 0 )return x; return gcd( y,x%y ); } int fastpow(int x,int y,int z) { int s = 1, base = x; while(y) { if(y&1) { s *= base; s %= z; } base *= base; base %= z; y = (y>>1); } return s; } int fun( int x,int y,int z,int mod) { int temp = gcd( y, z); return (fastpow(x,temp,mod)-1+mod)%mod; } int main() { int t; scanf( "%d",&t ); int a,n,m,k; while( t -- ) { scanf( "%d%d%d%d",&a,&n,&m,&k ); printf( "%d\n",fun( a, n, m, k)); } return 0; }
hdu-2685I won't tell you this is about number theory(数论)
标签:
原文地址:http://www.cnblogs.com/zhangchengc919/p/5440527.html