日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Can you find it(HDU-5478)

發布時間:2025/3/17 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。