結果

問題 No.3179 3 time mod
ユーザー jiangxinyang
提出日時 2025-06-13 22:01:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,128 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 196,664 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-14 01:41:58
合計ジャッジ時間 3,123 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int N = 200005;
const int INF = 0x3f3f3f3f;
__int128 extgcd(__int128 a, __int128 b, __int128 &x, __int128 &y) {
    if (!b) {
        x = 1;
        y = 0;
        return a;
    }
    __int128 x1, y1;
    __int128 g = extgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - (a / b) * y1;
    return g;
}
__int128 modinv(__int128 a, __int128 m) {
    __int128 x, y;
    __int128 g = extgcd(a < 0 ? a + m : a, m, x, y);
    if (g != 1) return -1;
    x %= m;
    if (x < 0) x += m;
    return x;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, p, q, r, a, b, c;
    cin >> n >> p >> q >> r >> a >> b >> c;
    __int128 inv = modinv(p % q, q), t = ((b - a) % q + q) % q * inv % q;
    __int128 x1 = a + p * t, m12 = p * q;
    __int128 inv2 = modinv(m12 % r, r), k = ((c - x1) % r + r) % r * inv2 % r;
    __int128 x0 = x1 + m12 * k, M = m12 * r;
    x0 %= M;
    if (x0 < 0) x0 += M;
    ll ans = 0;
    if (x0 <= n) ans = (ll)(((__int128)n - x0) / M + 1);
    cout << ans << "\n";
    return 0;
}
0