hdu5478 Can you find it(数学)

本文介绍了一种解决特定模数方程问题的方法,通过枚举变量a来求解b,进而验证n=2时方程是否成立。适用于给定素数C及参数k1、b1、k2的情形。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

思路:通过n=1的时候枚举a求出b,然后通过n=2的时候验证是否成立


#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL C,k1,b1,k2;
LL qpow(LL x,LL n,LL mod)
{
    LL ans=1;
    while(n>0)    
    {
        if(n&1)    ans=(ans*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    int T,cas=1;
    while(scanf("%lld%lld%lld%lld",&C,&k1,&b1,&k2)!=EOF)
    {
        int flag = 0;
        printf("Case #%d:\n",cas++);
        for(LL a = 1;a<C;a++)
        {
            LL b = C-qpow(a,k1+b1,C);
            LL x = qpow(a,2*k1+b1,C);
            LL y = qpow(b,k2+1,C);
            if((x+y)%C==0)
            {
                printf("%lld %lld\n",a,b);
                flag = 1;
            }
        }
        if(!flag)
            printf("-1\n");
    }
}


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
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值