HDU 5478 Can you find it
来源:互联网 发布:mp4 元数据 放头部 编辑:程序博客网 时间:2024/05/16 12:48
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
Recommend
hujie | We have carefully selected several similar problems for you: 5493 5492 5491 5490 5489
因为式子对所有的n都满足,我们把n=1和n=2代入.可以推出:a^k1=b^k2。b=c-a^(k1+b1) 。
我们从1到c-1枚举a。再求出b,然后判断a^k1是否等于b^k2即可。
#include<iostream>#include <algorithm>#include <cmath>#include <cstdio>using namespace std;typedef long long ll;ll fast(ll a,ll b,ll mod){ ll res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b/=2; } return res%mod;}int main(){ ll c,k1,b1,k2; int Case=0; while(cin>>c>>k1>>b1>>k2) { cout<<"Case #"<<++Case<<":"<<endl; ll i; int flag=0; for(i=1; i<c; i++) { ll ans=fast(i,k1,c); ll ans1=c-fast(i,k1+b1,c); ll ans2=fast(ans1,k2,c); if(ans==ans2) { flag=1; cout<<i<<" "<<ans1<<endl; } } if(!flag) puts("-1"); } return 0;}
0 0
- HDU 5478 Can you find it
- hdu 5478 Can you find it 测试
- HDU 5478 Can you find it
- [随机化] HDU 5478 Can you find it
- HDU 5478 Can you find it
- HDU Can you find it?
- hdu 5478 Can you find it(数论)
- HDU 5478 Can you find it 随机化 数学
- HDU/HDOJ 2141 Can you find it?
- HDU 1241 Can you find it?
- hdu 2141 can you find it?
- hdu 2142 Can you find it?
- HDU-2141 can you find it?
- hdu 2141 Can you find it?
- Can you find it? hdu 2141
- HDU 2141 Can you find it?
- hdu 2141 Can you find it ?
- hdu(2141) Can you find it?
- HDU 5475 An easy problem
- 这一年----On The Way
- 水
- linux定时任务的设置
- Android内存优化之OOM
- HDU 5478 Can you find it
- 跑马
- java 时间转换 将 util 时间转成 sql 时间
- java基础之集合List、Set、Map的区别
- opencv提取视频帧,将多张图片组合成视频(C++)
- HBase 1.1.2 Java 客户端 api(hbase 1.0 增删改查,建表、删表等)
- 19、linux软件管理之简述
- 获取 沙盒主路径 及其他下面的文件路径
- java 心跳机制