hdoj5478Can you find it【暴力枚举+快速幂】
来源:互联网 发布:路由器访客网络 编辑:程序博客网 时间:2024/05/12 00:09
Can you find it
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 980 Accepted Submission(s): 421
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
用G++提交4700msc++提交超时
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespace std;long long Pow(long long a,long long b,long long c){if(!b)return 1;long long t=Pow(a,b>>1,c);t=t*t%c;if(b&1)t=t*a%c;return t;}int main(){int t,i,j,k=1;long long k1,k2,b1,c;while(~scanf("%lld%lld%lld%lld",&c,&k1,&b1,&k2)){bool sign=true;printf("Case #%d:\n",k++);for(int a=1;a<c;++a){long long ans=Pow(a,k1+b1,c);long long b=c-ans;if(b>=1&&b<c){for(j=1;j<=10;++j){if((Pow(a,k1*j+b1,c)+Pow(b,k2*j-k2+1,c))%c!=0){break;}}if(j>10){sign=false;printf("%lld %lld\n",a,b);}}}if(sign){printf("-1\n");}}return 0;}
0 0
- hdoj5478Can you find it【暴力枚举+快速幂】
- HDU5478 Can you find it (快速幂)
- hdu5478 Can you find it+快速幂
- HDU5478Can you find it(快速幂)
- hdoj 5478 Can you find it 【找恒等式 + 快速幂】
- HDU5478——Can you find it(快速幂)
- 周中训练笔记+HDU5478Can you find it【快速幂】
- HDU5478 Can you find it 快速幂取模
- 杭电 2141 Can you find it?二分法+暴力查找
- hdu 2141 Can you find it?(暴力+二分)
- HDU 2141 Can you find it?(暴力+二分)
- hdu 2141 Can you find it?(二分+枚举)
- hdu2141Can you find it?
- can you find it?
- Can you find it?
- hdu2141Can you find it?
- Can you find it?
- HDU2141Can you find it?
- Android Studio 快捷键
- Activit实现TaskListener时注入service的问题
- json的各类转换总结
- PE文件详解(二)--节表和节
- 使用CvvImage类,实现MFC对话框显示视频
- hdoj5478Can you find it【暴力枚举+快速幂】
- iOS端实现登录输入框的三种思路(包含UIBezierPath等)
- Android中定时执行任务的3种实现方法
- PE文件详解(三)--区块描述、对齐值以及RVA
- Java基础学习笔记4
- Linux文件系统
- Ubuntu打开右上脚网络小图标
- AFNetworking GET 请求 方法封装及调用
- PE文件详解(四)--导入表1