結果

問題 No.1396 Giri
ユーザー Plan8Plan8
提出日時 2021-02-14 22:02:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 2,720 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 205,260 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2023-09-29 15:31:43
合計ジャッジ時間 4,286 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 140 ms
10,832 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 141 ms
10,808 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 11 ms
4,376 KB
testcase_19 AC 71 ms
7,196 KB
testcase_20 AC 100 ms
8,748 KB
testcase_21 AC 127 ms
10,140 KB
testcase_22 AC 139 ms
10,824 KB
testcase_23 AC 139 ms
10,868 KB
testcase_24 AC 141 ms
10,880 KB
testcase_25 AC 139 ms
10,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 998244353;

template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}

long long mul_modp(long long a, long long b){
    // a*b mod p
    return ((a % MOD) * (b % MOD)) % MOD;
}

long long modinv(long long a){
    // a^{-1} = 1/a mod p (拡張Euclidの互除法)
    long long b = MOD, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

long long div_modp(long long a, long long b){
    // a/b mod p
    return mul_modp(a, modinv(b));
}

vector<int> sieve_eratosthenes(int n){
    vector<int> ret(n+1); for(int i=0; i<=n; ++i) ret[i] = i;
    for(int i=2; i*i<=n; i++){
        if(ret[i] < i) continue;
        for(int j=i*i; j<=n; j+=i) ret[j] = min(ret[j], i);
    }
    return ret;
}

vector<Pair> factorize(int n, VI& sieve){
    vector<Pair> v;
    while(n>1){
        if(v.empty() || v.back().first != sieve[n]) v.emplace_back(sieve[n],1);
        else{
            v.back().second++;
        }
        n /= sieve[n];
    }
    return v;
}

void Main(){
    int N; cin >> N;
    VI sieve = sieve_eratosthenes(N);
    VI fact(N+1,0);
    REP(i,N){
        auto v = factorize(i+1, sieve);
        for(auto& [x,n] : v){
            chmax(fact[x], n);
        }
    }

    ll ans = 1;
    REP(i,N){
        REP(j,fact[i+1]) (ans *= i+1) %= MOD;
    }
    RREP(i,N){
        if(sieve[i+1] == i+1){
            ans = div_modp(ans,i+1);
            break;
        }
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}
0