2015 ACM/ICPC Asia Regional Shanghai Online
引用一下公式:http://blog.csdn.net/queuelovestack/article/details/48754331
#include <stdio.h>
#define ll long long
ll mod(ll a, ll b, ll n){
ll ret = 1;
while(b > 0){
if(b & 1) ret = (ret * a) % n;
b = b >> 1;
a = (a * a) % n;
}
return ret;
}
int main()
{
ll C, k1, b1, k2, bk2, b, ak1, i, k;
bool flag;
k = 1;
while(~scanf("%lld %lld %lld %lld", &C, &k1, &b1, &k2))
{
printf("Case #%lld:\n", k++);
flag = 0;
for(i = 1;i < C;i++)
{
ak1 = mod(i, k1, C);
b = C - mod(i, k1 + b1, C);
bk2 = mod(b, k2, C);
if(ak1 == bk2){
printf("%lld %lld\n", i, b);
flag = 1;
}
}
if(!flag) printf("-1\n");
}
}