题意:
求满足题目式子的所有a,b对
思路:
暴力打表可以发现,若满足n=1和n=2,则对于大于2的n都满足
因为a和b都小于c,直接暴力所有可能的情况
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll c,k1,k2,b1;
int casnum=1;
struct node
{
ll a,b;
node(ll a_,ll b_)
{
a=a_;b=b_;
}
};
vector<struct node>v;
ll fpow(ll a,ll b)
{
ll ans=1;
ll tmp=a%c;
while(b)
{
if(b&1)
ans=ans*tmp%c;
tmp=tmp*tmp%c;
b/=2;
}
return ans;
}
int main()
{
while(scanf("%lld%lld%lld%lld",&c,&k1,&b1,&k2)!=EOF)
{
v.clear();
for(ll a=1;a<c;a++)
{
ll p=fpow(a,k1+b1);
ll b=c-p;
if((fpow(a,2*k1+b1)+fpow(b,k2+1))%c==0)
v.push_back(node(a,b));
}
printf("Case #%d:\n",casnum++);
if(v.size()==0)
{
printf("-1\n");
continue;
}
for(int i=0;i<v.size();i++)
{
printf("%lld %lld\n",v[i].a,v[i].b);
}
}
}