Can you find it(HDU-5478)
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(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.
Examples
Input
23 1 1 2
Output
Case #1:
1 22
題意:給出一個質數 c,三個正整數 k1,b1,k2,對于公式 ,若能找出最小的 a,b 則輸出,若找不出則輸出 -1
思路:公式題
對于公式?
當 n=1 時,?①
當 n=2 時,?②
令??* ②,?③
令 ③-②,
即:
由于 a、b < c,只需要枚舉 a 的值(1~c-1),通過快速冪計算?、,從而算出 b,再求出?,比較??是否等于??即可
Source Program
#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #define PI acos(-1.0) #define E 1e-6 #define MOD 1000000007 #define INF 0x3f3f3f3f #define N 500001 #define LL long long using namespace std; LL Pow_Mod(LL a, LL b, LL m) {LL res=1;while(b){if(b&1)res=(res*a)%m;a=(a*a)%m;b>>=1;}return res; }int main(){LL c,k1,b1,k2;int Case=1;while(scanf("%lld%lld%lld%lld",&c,&k1,&b1,&k2)!=EOF){bool flag=false;printf("Case #%d:\n",Case++);for(LL i=1;i<=c-1;i++){LL a=Pow_Mod(i,k1,c);LL b=c-Pow_Mod(i,k1+b1,c);LL temp=Pow_Mod(b,k2,c);if(a==temp){flag=true;printf("%lld %lld\n",i,b);}}if(!flag)printf("-1\n");}return 0; }?
總結
以上是生活随笔為你收集整理的Can you find it(HDU-5478)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Menagerie(AtCoder-22
- 下一篇: I Hate It(HDU-1754)