exCRT
#include <bits/stdc++.h>
#ifndef _MSVC_LANG
#define int __int128
#define gcd __gcd
#define lcm(a,b) a/gcd(a,b)*b
#else
#define int long long
#endif
#define cint const int&
using namespace std;

template<typename T>
T exgcd(const T& a, const T& b, T& x, T& y) {//to calc a*x + b*y = gcd(a,b)
    if (!b) return x = 1, y = 0, a;
    const T g = exgcd(b, a % b, x, y);//b(x-a/b*y) + ay  = gcd(a,b)
    auto tmp = x - a / b * y;
    x = y;
    y = tmp;
    return g;
}
namespace exCRT {
    template<typename T>
    struct equation { int r, m; };
    //res: =1:not
    //     =0:can
    template<typename T>
    inline bool merge(equation<T>& a, const equation<T>& b) {
        const T d = gcd(a.m, b.m);
        T k1, k2;
        exgcd(a.m / d, b.m / d, k1, k2);
        if ((b.r - a.r) % d) return 1;
        const auto lcms = lcm(a.m, b.m);
        k1 %= lcms;
        k1 *= (b.r - a.r) / d;
        k1 %= lcms;
        a.r += k1 * a.m;
        a.m = lcms;
        ((a.r %= a.m) += a.m) %= a.m;
        return 0;
    }
}

long long a, b, n;
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    n--;
    cin >> a >> b;
    exCRT::equation<int> ans{ b,a };
    while (n--) {
        cin >> a >> b;
        exCRT::merge(ans, { b,a });
    }
    cout << (long long)ans.r % (long long)ans.m;
    return 0;
}

就是合并方程

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇