結果

問題 No.1396 Giri
ユーザー だれ
提出日時 2021-02-28 22:12:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,699 bytes
コンパイル時間 4,404 ms
コンパイル使用メモリ 250,304 KB
最終ジャッジ日時 2025-01-19 08:44:32
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define i64 long long
template<class T>
bool chmin(T& a, const T& b) { return (b < a) ? (a = b, true) : false; }
template<class T>
bool chmax(T& a, const T& b) { return (b > a) ? (a = b, true) : false; }

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

vector<bool> erat(long long n)
{
    vector<bool> res(n + 1, true);
    res[0] = false;
    res[1] = false;
    for(long long i = 2; i <= n; i++)
    {
        if(res[i])
        {
            if(i * i <= n)
            {
                for(long long j = i * i; j <= n; j += i)
                {
                    res[j] = false;
                }
            }
        }
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    auto f = erat(n);
    i64 ans = 1;
    int k = 1;
    for (int i = 1; i <= n; i++)
    {
        if(f[i])
        {
            auto u = n;
            auto x = n / i;
            if(x == 1) k = i;
            while(u >= i)
            {
                ans *= i;
                ans %= 998244353;
                u /= i;
            }
        }
    }
    auto x = modpow(k, 998244351, 998244353);
    ans *= x;
    ans %= 998244353;
    cout << ans << endl;
}
0