题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5478
Can you find it
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.
Sample Input
23 1 1 2
Sample Output
Case #1:
1 22
题目大意:
给你C,k1,k2,b1,按字典序输出满足的所有(a,b)对,否则输出-1
思路:
//题目思路 来自于https://blog.csdn.net/sdz20172133/article/details/86500380
This is the code
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long //1844674407370955161
#define INT_INF 0x7f7f7f7f //2139062143
#define LL_INF 0x7f7f7f7f7f7f7f7f //9187201950435737471
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf,sscanf, getchar, fgets之类的一起使用了。
const int dr[]={0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]={-1, 1, 0, 0, -1, 1, -1, 1};
LL quick_pow(LL a,LL n,LL mod)
{
LL ret=1;
while(n)
{
if(n&1)
ret=ret*a%mod;
a=a*a%mod;
n>>=1;
}
return ret%mod;
}
int main()
{
LL c,k1,b1,k2;
int k=1;
while(~scanf("%lld%lld%lld%lld",&c,&k1,&b1,&k2))
{
bool flag=true;
printf("Case #%d:\n",k++);
for(LL i=1;i<c;++i)
{
LL a=quick_pow(i,k1,c);
LL tem=c-quick_pow(i,k1+b1,c);
LL b=quick_pow(tem,k2,c);
if(a==b)
{
flag=false;
printf("%lld %lld\n",i,tem);
}
}
if(flag)
printf("-1\n");
}
return 0;
}