题意略。
思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define MAXN 200005
using namespace std;
LL C, k1, b1, k2;
LL quick_mod(LL x, LL y, LL mod){
if (y == ) return ;
LL res = quick_mod(x, y >> , mod);
res = res * res % mod;
if (y & ){
res = res * x % mod;
}
return res;
}
LL a[MAXN][];
LL b[MAXN];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int cas = ;
while (~scanf("%I64d%I64d%I64d%I64d", &C,&k1, &b1, &k2)){
printf("Case #%d:\n", cas++);
int t = ;
for (int i = ; i < C; i++){
LL m = quick_mod((LL)i, k1 + b1, C);
if (m == ) continue;
a[++t][] = i;
a[t][] = C - m;
b[t] = m;
}
bool noans = true;
for (LL i = ; i <= t; i++){
LL pa = b[i];
LL pa_k1 = quick_mod(a[i][], k1, C);
LL pb_k2 = quick_mod(a[i][], k2, C);
LL pb = a[i][];
LL xx = pa;
LL yy = pb;
// pb_k2 = quick_mod(pb_k2, 10000, C);
LL x = pa_k1, y = pb_k2;
bool flag = false;
for (int j = ; j <= ; j++){
pa = pa * x % C;
pb = pb * y % C;
if (pa == xx && pb == yy){
break;
}
if ((pa + pb) % C != ){
flag = true;
break;
}
}
if (flag) continue;
printf("%I64d %I64d\n", a[i][], a[i][]);
noans = false;
}
if (noans){
printf("-1\n");
}
}
}