您的位置:首页 > 其它

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息