hdu 5478 Can you find it 测试
2015-10-01 09:08
260 查看
Can you find it
[b]Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 651 Accepted Submission(s): 306
[/b]
[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
#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #define ll long long using namespace std; int c; int cal(int n,ll t){ int ans = 1; while(t){ if(t&1) ans = (ll)ans*n%c; n = (ll)n*n%c; t/=2; } return ans; } int chk[10]={ 11, 23, 97 }; int main(){ int tt=1,k1,b1,k2; while(scanf("%d%d%d%d",&c,&k1,&b1,&k2)!=EOF){ printf("Case #%d:\n",tt++); int ok = 0,b,flag,x,y,z,a; for(int i = 1;i < c; i++){ a = i; x = cal(a,k1+b1); flag = 1; b = (c-x); if(b < 1 || b >= c) continue; x = cal(a,k1); y = cal(b,k2); if(x != y) flag = 0; if(flag){ ok = 1; printf("%d %d\n",a,b); } } if(ok==0)printf("-1\n"); } return 0; }
相关文章推荐
- Android之使用Http协议实现文件上传功能
- 通晓网络测试常用命令
- Nodejs学习笔记之测试驱动
- 可以测试javascript运行效果的代码
- 使用php测试硬盘写入速度示例
- python 测试实现方法
- 举例详解PHP脚本的测试方法
- Php-Redis安装测试笔记
- mysql压力测试脚本实例
- JavaScript 组件之旅(四):测试 JavaScript 组件
- Android触屏测试实例代码
- 解析libcurl在android下的移植、编译与测试
- 几个比较实用的JavaScript 测试及效验工具
- Java中对AtomicInteger和int值在多线程下递增操作的测试
- Python实现测试磁盘性能的方法
- python自动化测试实例解析
- Python之PyUnit单元测试实例
- Appium自动化测试系列2- 写一个Python测试脚本来测试一下YY语音
- IOS UI Automation 学习之常用类,方法和模拟手势
- 测试时尚