Problem Description
Given a prime number C(1≤C≤2×105),
and three integers k1, b1, k2 (1≤k1,k2,b1≤109).
Please find all pairs (a, b) which satisfied the equation ak1⋅n+b1+ bk2⋅n−k2+1 =
0 (mod C)(n = 1, 2, 3, ...).
枚举a,把n=1代入,算出b。根据a,b,代入n=2,如果等式成立,就输出。
#include <iostream>
using namespace std;
#define ll long long
const int maxn = 100010;
ll c,k1,B1,k2;
ll p;
ll Quick_Pow(ll a,ll n) {
ll ret=1;
ll temp=a%p;
while (n){
if (n&1) ret=ret*temp%p;
temp=temp*temp%p;
n>>=1;
}
return ret;
}
int main(){
int cas = 0;
while(cin>>c>>k1>>B1>>k2){
cas++;
printf("Case #%d:\n",cas);
bool hassol=0;
for(int a=1;a<c;a++){
//a^(k1*n+b1)
//b^(k2*n-k2+1)
p=c;
ll a1 = Quick_Pow(a,k1+B1);
ll b = c - a1;
bool ok=1;
ll an=a1;
ll bn=b;
ll atmp = Quick_Pow(a,k1);
ll btmp = Quick_Pow(b,k2);
an*=atmp; bn*=btmp;
an%=c; bn%=c;
if( (an+bn)%c==0 ){
hassol=1;
printf("%I64d %I64d\n",a,b);
}
}
if(!hassol){
printf("-1\n");
}
}
return 0;
}