HDU 5478 Can you find it
2015-09-27 11:36
387 查看
Can you find it
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 450 Accepted Submission(s): 208
[align=left]Problem Description[/align]
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, ...).
[align=left]Input[/align]
There are multiple test cases (no more than 30). For each test, a single line contains four integers C, k1, b1, k2.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
23 1 1 2
[align=left]Sample Output[/align]
Case #1:
1 22
[align=left]Source[/align]
2015 ACM/ICPC Asia Regional Shanghai Online
[align=left]Recommend[/align]
hujie
首先想n为1,2,3……都要成立,所以先保证n=1成立,然后验证其他是否成立,把等式左边的b那一项移到右边,除一下,发现每次增量都是a^k1 和b^k2 所以只要n=2成立,后面的都成立。
下回这种题不要怕,还是可以做的。
#include<queue> #include<math.h> #include<stdio.h> #include<string.h> #include<string> #include<iostream> #include<algorithm> using namespace std; #define N 1234567 #define M 12 int c, k1, b1, k2; bool flag; int quickpow(int m,int n,int k)// m^n % k { int b = 1; while (n > 0) { if (n & 1) b = (b*m)%k; n = n >> 1 ; m = (m*m)%k; } return b; } int main() { int tt = 1; int b; while(~scanf("%d %d %d %d", &c, &k1, &b1, &k2)) { printf("Case #%d:\n", tt++); flag = 0; for(int a = 1; a < c; a++) { b = c - quickpow(a,k1+b1,c); if( ( quickpow(a, k1*2+b1, c) + quickpow(b, k2*2-k2+1, c) ) %c == 0) { printf("%d %d\n",a,b); flag = 1; } } if(flag == 0) printf("-1\n"); } return 0; }
相关文章推荐
- iOS开发之xib技巧介绍
- 数据结构,多项式运算,C++,链表
- 倒置链表
- 14 Best Open Source Web Application Vulnerability Scanners
- HTTP协议状态码学习
- JavaScript高级程序设计之引用类型之单体内置对象之Math对象第5.7.2讲笔记
- 一元多项式的加减乘除运算,C++语言描述,数据结构实验
- GRUB应用
- 算法珠玑算法总结(转)
- [数据结构]Hash表初学(数组链表)
- Java------网络通信编程 之 菜鸟新手的学习总结
- 3.3.5 使用HtmlDiff对象
- HDU 25919 新生晚会(水题组合问题)
- 内存管理里的一些小细节
- 【LeetCode 153: Find Minimum in Rotated Sorted Array】
- 动态规划之背包问题初研究
- 3.3.5 使用HtmlDiff对象
- KissXML解析
- 在C/C++中调用python的简单笔记part 1
- 对实训以及实训后的看法