提交记录 22494


用户 题目 状态 得分 用时 内存 语言 代码长度
czxb2 test. 自定义测试 Accepted 100 333.478 ms 40 KB C++17 1.67 KB
提交时间 评测时间
2024-09-13 09:00:31 2024-09-13 09:00:34
#include <bits/stdc++.h>
using namespace std;

using u64 = uint64_t;
using u32 = uint32_t;
using ll = long long;


struct Montgomery {
    u32 m, mx2, m_inv;
    u64 r2;
    static pair<ll, ll> exgcd(u64 a, u64 b) {
        if (!b) return {1, 0};
        auto [x, y] = exgcd(b, a % b);
        return {y, x - a / b * y};
    }
    Montgomery(u32 _m = 1) {
        assert(_m && _m < (1 << 30));
        const u64 r = 1ull << 32;
        m = _m;
        mx2 = m * 2;
        m_inv = -exgcd(m, r).first;
        r2 = ((r % m) << 32) % m;
    }
    u64 reduce(u64 x) {
        return (x + u32(u32(x) * m_inv) * u64(m)) >> 32;
    }
    u32 transform(u32 x) {
        return reduce(u64(x) * r2);
    }
    u32 chk(u32 x) {
        return x < mx2 ? x : x - mx2;
    }
    u32 output(u64 x) {
        x = reduce(x);
        if (x >= mx2) x -= mx2;
        if (x >= m) x -= m;
        return x;
    }
};

u64 myclock() { return chrono::steady_clock::now().time_since_epoch().count(); }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    u64 tmp = 0 * rng();
    u32 m = 998244353 ^ tmp;
    m ^= tmp;

    if (0)
    {
        u64 t = myclock();

        Montgomery mod(m);
        u64 one = mod.transform(1), x = 0, ans = one;
        for (int i = 1; i <= 100000000; i++) {
            x = mod.chk(x + one);
            ans = mod.reduce(ans * x);
        }
        cout << mod.output(ans) << "\n";

        cout << myclock() - t << "\n";
    }
    else
    {
        u64 t = myclock();

        u64 ans = 1;
        for (int i = 1; i <= 100000000; i++)
            ans = ans * i % m;
        cout << ans << "\n";
        
        cout << myclock() - t << "\n";
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1333.478 ms40 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2024-10-05 10:23:12 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用