Can you find it
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 651 Accepted Submission(s): 306
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, ...).
Input
There are multiple test cases (no more than 30). For each test, a single line contains four integers C, k1, b1, k2.
Output
First, 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) . If there is not a pair (a, b), please output -1.
Please output all pairs (a, b) in lexicographical order. (1≤a,b<C) . If there is not a pair (a, b), please output -1.
Sample Input
23 1 1 2
Sample Output
Case #1: 1 22
Source
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define ll long long
using namespace std;
int c;
int cal(int n,ll t){
int ans = 1;
while(t){
if(t&1) ans = (ll)ans*n%c;
n = (ll)n*n%c;
t/=2;
}
return ans;
}
int chk[10]={
11,
23,
97
};
int main(){
int tt=1,k1,b1,k2;
while(scanf("%d%d%d%d",&c,&k1,&b1,&k2)!=EOF){
printf("Case #%d:\n",tt++);
int ok = 0,b,flag,x,y,z,a;
for(int i = 1;i < c; i++){
a = i;
x = cal(a,k1+b1);
flag = 1;
b = (c-x);
if(b < 1 || b >= c) continue;
x = cal(a,k1);
y = cal(b,k2);
if(x != y) flag = 0;
if(flag){
ok = 1;
printf("%d %d\n",a,b);
}
}
if(ok==0)printf("-1\n");
}
return 0;
}