可以发现一个a对应一个b
枚举a
n=1时求出b
然后随机化验证是否恒成立
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;
ll P,k1,k2,b1;
inline ll Pow(ll a,int b){
ll ret=1;
for (;b;b>>=1,a=a*a%P)
if (b&1)
ret=ret*a%P;
return ret;
}
inline bool check(ll a,ll b){
int Test=300;
while (Test--)
{
int n=rand()%P+1;
if ((Pow(a,(k1*n+b1)%(P-1))+Pow(b,(k2*(n-1)+1)%(P-1)))%P!=0)
return 0;
}
return 1;
}
int main()
{
int a,b,_t=0;
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
while (~scanf("%lld%lld%lld%lld",&P,&k1,&b1,&k2))
{
int flag=0;
printf("Case #%d:\n",++_t);
for (int i=1;i<P;i++)
{
a=i; b=P-Pow(a,k1+b1);
if (check(a,b))
flag=1,printf("%d %d\n",a,b);
}
if (!flag) printf("-1\n");
}
return 0;
}