hdu 5478 Can you find it 测试

Can you find it

Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 651    Accepted Submission(s): 306


Problem Description
Given a prime number C(1C2×105) , and three integers k1, b1, k2 (1k1,k2,b1109) . Please find all pairs (a, b) which satisfied the equation ak1n+b1 + bk2nk2+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. (1a,b<C) . If there is not a pair (a, b), please output -1.
 

Sample Input
  
  
23 1 1 2
 

Sample Output
  
  
Case #1: 1 22
 

Source
 


#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;

}













  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GDRetop

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值