HDU 5478 Can you find it(快速幂)——2015 ACM/ICPC Asia Regional Shanghai Online
2015-09-26 21:24
615 查看
Can you find it
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)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
Source
2015 ACM/ICPC Asia Regional Shanghai Online
/*********************************************************************/
题意:给你C,k1,k2,b1,按字典序输出满足
的所有(a,b)对
解题思路:因为
对于任意n均满足,故n=1的情况也是符合的,故可得
①
而n=2的情况也是符合的,可得
②
因为①式mod C = 0 ,所以①式乘以一个数mod C 仍为0,不妨①式*
,可得
所以,我们只需遍历一遍a的取值(1~C-1),利用快速幂计算出
,以及
,再根据式①可以算出b,再用一次快速幂求出
,比较
(mod
C)是否等于
(mod C)即可
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<stack> #include<math.h> #include<vector> #include<map> #include<set> #include<stdlib.h> #include<cmath> #include<string> #include<algorithm> #include<iostream> #define exp 1e-10 using namespace std; const int N = 200001; const int inf = 1000000000; const int mod = 2009; __int64 Quick_Mod(int a, int b, int m) { __int64 res = 1,term = a % m; while(b) { if(b & 1) res = (res * term) % m; term = (term * term) % m; b >>= 1; } return res%m; } int main() { int C,k1,b1,k2,i,k=1; __int64 a,b,s; bool flag; while(~scanf("%d%d%d%d",&C,&k1,&b1,&k2)) { flag=false; printf("Case #%d:\n",k++); for(i=1;i<C;i++) { a=Quick_Mod(i,k1,C); b=C-Quick_Mod(i,k1+b1,C); s=Quick_Mod(b,k2,C); //printf("##%I64d %I64d\n",a,s); if(a==s) flag=true,printf("%d %I64d\n",i,b); } if(!flag) puts("-1"); } return 0; }菜鸟成长记
相关文章推荐
- 2015 ACM/ICPC Asia Regional Shanghai Online
- 2015 ACMICPC Asia Regional Shanghai Online
- 循环引用之【#import】【@class】和循环【retain】之【assign】
- HDU 5477.A Sweet Journey【2015 ACM/ICPC Asia Regional Shanghai Online】【9月26】
- HDU 5475.An easy problem【思路】【2015 ACM/ICPC Asia Regional Shanghai Online】【9月26】
- LeetCode(11) Container With Most Water
- LeetCode(11) Container With Most Water
- signal(SIGCLD,SIG_IGN) http://blog.csdn.net/cffishappy/article/details/7005115
- HDU 5476 Explore Track of Point 几何题 —— 2015 ACM/ICPC Asia Regional Shanghai Online
- HDU 5477 A Sweet Journey(本场的最水题,过程处理好是关键)——2015 ACM/ICPC Asia Regional Shanghai Online
- DeepMind背后的人工智能:深度学习原理初探
- HDU 5475 An easy problem(用大数模板,你就上当了)——2015 ACM/ICPC Asia Regional Shanghai Online
- 2015 ACM/ICPC Asia Regional Shanghai Online 1010题
- HDU 5478 Can you find it (卡常数)2015 ACM/ICPC Asia Regional Shanghai Online
- aircrack使用
- Clairewd’s message--hdu4300(Next数组的运用)
- CoCreateInstance of OLE control failed
- 第十二篇:关于main中的两个参数的使用请况
- epoll_wait 时 POLLERR 与 POLLIN 同时返回的现象解析
- ADB not responding. You can wait more,or kill"abd.exe“。。。。。