HDU5478取模恒等式

这题刚开始自己推公式,推了好久并没有推出来,最后队友A的,据说是直接让n等于1,

然后用快速幂去求a得幂,然后直接用c去减这个值就是b,然后再用50个不同的n值去验证

,如果等式均成立,即使一对符合的值,个人不喜欢做这些感觉逻辑不是很严密的题,但是事实就是

这样,往往有些题逻辑不会很严密的让你感觉绝对对,因为由于学术有限,很多东西我们是很难验证的,

所以有时做题也需要猜想。

贴上队友代码:

#include<algorithm>
#include<iostream>
#include<limits.h>
#include<stdlib.h>
#include<string.h>
#include<complex>
#include<cstring>
#include<iomanip>
#include<stdio.h>
#include<bitset>
#include<cctype>
#include<math.h>
#include<string>
#include<time.h>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>

#define LL long long
#define ULL unsigned long long

using namespace std;
const int mod = 1000000007;
const double PI = acos(-1.0);
const double E = exp(1.0);
const int M = 200005;

LL Pow(LL x, LL n, int Mod)
{
    LL ans = 1;
    while( n ){
        if(n & 1)
            ans = (ans * x) % Mod;
        x = (x * x) % Mod;
        n /= 2;
    }
    return ans;
}

int main()
{
    int t;
    int c;
    LL k1, k2, b1;
    LL b;
    int cas = 1;
    while( cin >> c >> k1 >> b1 >> k2 ){
        LL ans, n;
        cout << "Case #" << cas++ << ":" << endl;
        bool OK = 1;
        for(LL i = 1; i < c; ++i){
            LL temp = Pow(i, k1 + b1, c);
            b = c - temp;
            bool ok = 1;
            for(LL j = 2; j < 50; ++j){
                LL ans1 = Pow(i, k1 * j + b1, c);
                LL ans2 = Pow(b, k2 * j - k2 + 1, c);
                ans = (ans1 + ans2) % c;
                //cout << ans1 << " fdafas" << ans2 << endl;
                if(ans){
                    ok = 0;
                    break;
                }
            }
            if(ok){
                OK = 0;
                cout << i << " " << b << endl;
            }
        }
        if(OK)
            puts("-1");

    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值