hdu5478 Can you find it
来源:互联网 发布:spark java api 中文 编辑:程序博客网 时间:2024/05/01 16:38
Can you find it
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 822 Accepted Submission(s): 365
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.
Please output all pairs (a, b) in lexicographical order.
Sample Input
23 1 1 2
Sample Output
Case #1:1 22
Source
2015 ACM/ICPC Asia Regional Shanghai Online
题意:求出最小的a和对应的b满足题目所给式子。
分析:刚看到这题时也想到了快速幂,但一看数据范围,感觉肯定会超时,想了很久,未果,参考大牛博客,就是快速幂。详解见这--某大牛博客
#include <iostream>#include <cstdio>#include <cstring>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <cmath>#include <algorithm>using namespace std;const double eps = 1e-6;const double pi = acos(-1.0);const int INF = 0x3f3f3f3f;const int MOD = 1000000007;#define ll long long#define CL(a) memset(a,0,sizeof(a))ll C,k1,b1,k2;ll a,b;ll mod_pow(ll x, ll y, ll mod){ ll re=1; while (y) { if (y&1) re=re*x%C; x=x*x%C; y>>=1; } return re;}int main (){ int cas=1; while (cin>>C>>k1>>b1>>k2) { cout<<"Case #"<<cas++<<":"<<endl; bool flag=false; for (a=1; a<C; a++) { b = C-mod_pow(a, k1+b1, C); if ((mod_pow(a,k1,C)*(C-b)%C+mod_pow(b,k2,C)*b%C)%C==0) cout<<a<<" "<<b<<endl,flag=true; } if (!flag) cout<<"-1"<<endl; } return 0;}
0 0
- HDU5478 Can you find it
- hdu5478 Can you find it
- HDU5478 Can you find it 快速幂取模
- hdu5478 Can you find it(数学规律)
- HDU5478 Can you find it (快速幂)
- hdu5478 Can you find it(数学)
- hdu5478 Can you find it+快速幂
- HDU5478 Can you find it【同余问题】
- HDU5478——Can you find it(快速幂)
- can you find it?
- Can you find it?
- Can you find it?
- Can you find it?
- can you find it?
- Can you find it?
- can you find it?
- Can you find it?
- Can you find it?
- 使用Microsoft Visual Studio编译LLVM
- Binder进程间通信系统
- poj3020
- leetcode--single number.
- 使用命令备份和恢复OSX系统分区
- hdu5478 Can you find it
- C++Primer第五版 练习11.28(解答)
- HTML基本结构、头部元素
- 编写一个C#程序,要求从键盘输入10个数存放在数组中,分别求出最大数和最小数存放在第一第二个元素里
- 解析JSON数据系列1:在网页上显示Json数据
- UML——类图
- min 宏定义 避免副作用
- leetcode-reverse words in a string
- C++Primer第五版 练习11.31-32(解答)