题意
问你有多少对数,满足a^(k1⋅n+b1) + b^(k2⋅n−k2+1) = 0 (mod C)
题解:
首先你要知道,对于每个a只有唯一对应的b可以满足这个式子,因为当n=1的时候,a^(k1+b1)+b = kk*C
由于b是小于c的,所以只有一个
所以我们可以求出b来,然后我们怎么check这个b究竟是不是呢?
随机化10个数,然后随便check就好了
//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100006
#define mod 1000000007
#define eps 1e-9
#define e exp(1.0)
#define PI acos(-1)
const double EP = 1E-10 ;
int Num;
//const int inf=0x7fffffff;
const ll inf=999999999;
inline ll read()
{
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
//*************************************************************************************
ll fMul(int m,ll n,int k)
{
ll cc = m;
ll b = 1;
while (n > 0)
{
if (n & 1LL)
{
b = (b*cc);
if(b>=k)
b%=k;
}
n = n >> 1LL ;
cc = (cc*cc)%k;
if(cc>=k)cc%=k;
}
return b;
}
int main()
{
//freopen("out.txt","r",stdin);
//freopen("out2.txt","w",stdout);
srand(time(NULL));
int tot = 1;
int c ,k1 ,b1 ,k2;
while(scanf("%d%d%d%d",&c,&k1,&b1,&k2)!=EOF)
{
printf("Case #%d:\n",tot++);
int flag1 = 0;
for(int i=1;i<c;i++)
{
int j=c-fMul(i,k1*1+b1,c);
int flag = 1;
for(int k=1;k<=15;k++)
{
ll tt = rand()%c+1;
ll ttt1 = k1, ttt2 = k2,ttt3 = b1;
if((fMul(i,ttt1*tt+ttt3,c)+fMul(j,ttt2*tt-ttt2+1LL,c))%c!=0)
{
flag = 0;
break;
}
}
if(flag)
{
printf("%d %d\n",i,j);
flag1=1;
}
}
if(!flag1)
printf("-1\n");
}
}