hdu 5478 Can you find it 数学(思维)

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5478

Can you find it

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.

Sample Input

23 1 1 2

Sample Output

Case #1:

1 22

题目大意:

给你C,k1,k2,b1,按字典序输出满足的所有(a,b)对,否则输出-1

思路:

//题目思路 来自于https://blog.csdn.net/sdz20172133/article/details/86500380

This is the code

#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long     //1844674407370955161
#define INT_INF 0x7f7f7f7f      //2139062143
#define LL_INF 0x7f7f7f7f7f7f7f7f //9187201950435737471
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf,sscanf, getchar, fgets之类的一起使用了。
const int dr[]={0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]={-1, 1, 0, 0, -1, 1, -1, 1};
LL quick_pow(LL a,LL n,LL mod)
{
    LL ret=1;
    while(n)
    {
        if(n&1)
            ret=ret*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ret%mod;
}
int main()
{
    LL c,k1,b1,k2;
    int k=1;
    while(~scanf("%lld%lld%lld%lld",&c,&k1,&b1,&k2))
    {
        bool flag=true;
        printf("Case #%d:\n",k++);
        for(LL i=1;i<c;++i)
        {
            LL a=quick_pow(i,k1,c);
            LL tem=c-quick_pow(i,k1+b1,c);
            LL b=quick_pow(tem,k2,c);
            if(a==b)
            {
                flag=false;
                printf("%lld %lld\n",i,tem);
            }
        }
        if(flag)
            printf("-1\n");
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值