https://vjudge.net/contest/237063#problem/K
Given a prime number
C(1≤C≤2×105)C(1≤C≤2×105), and three integers k1, b1, k2
(1≤k1,k2,b1≤109)(1≤k1,k2,b1≤109). Please find all pairs (a, b) which satisfied the equation
ak1⋅n+b1ak1⋅n+b1 +
bk2⋅n−k2+1bk2⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...).
InputThere are multiple test cases (no more than 30). For each test, a single line contains four integers C, k1, b1, k2.OutputFirst, please output "Case #k: ", k is the number of test case. See sample output for more detail.
Please output all pairs (a, b) in lexicographical order. (1≤a,b<C)(1≤a,b<C). If there is not a pair (a, b), please output -1.Sample Input
23 1 1 2Sample Output
Case #1: 1 22
#include <bits/stdc++.h>
using namespace std;
long long c, k1, b1, k2;
long long quickpow(long long a, long long b)
{
long long ans = 1;
long long base = a;
while (b)
{
if (b & 1)
ans = ans*base%c;
base =base*base%c;
b = b >> 1;
}
return ans;
}
int main()
{
int T = 0;
while (~scanf("%lld %lld %lld %lld", &c, &k1, &b1, &k2))
{
printf("Case #%d:\n", ++T);
bool flag = 0;
for (long long a = 1; a < c; a++)
{
// 取特殊 n = 1 时 枚举 a 求对应的唯一 b
long long u = k1 + b1;
long long v = quickpow(a, u) % c;
long long b = c - v;
if (b == c)
continue;
if (quickpow(a, k1) == quickpow(b, k2))
{ // 每次递推乘相同的数 仍为C的倍数
printf("%lld %lld\n", a, b);
flag = 1;
}
}
if (!flag)
printf("-1\n");
}
return 0;
}