結果

問題 No.1529 Constant Lcm
ユーザー 8UqsVg4r8UqsVg4r
提出日時 2021-06-04 22:50:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 3,000 ms
コード長 10,779 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 189,244 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 11:07:21
合計ジャッジ時間 3,372 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 11 ms
6,944 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 10 ms
6,940 KB
testcase_14 AC 7 ms
6,940 KB
testcase_15 AC 7 ms
6,944 KB
testcase_16 AC 6 ms
6,940 KB
testcase_17 AC 4 ms
6,944 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 7 ms
6,940 KB
testcase_20 AC 12 ms
6,940 KB
testcase_21 AC 12 ms
6,944 KB
testcase_22 AC 12 ms
6,940 KB
testcase_23 AC 12 ms
6,944 KB
testcase_24 AC 12 ms
6,940 KB
testcase_25 AC 12 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/////////////////////////////////////////////////
/////             Give me AC!!!!            /////
/////////////////////////////////////////////////
//↑これじゃ気合いが足りない!
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////             お願いしますACをくださいそうじゃないと僕泣きますお願いしますACをくださいJudge様....            /////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include<bits/stdc++.h>
#include <type_traits>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<vector<ll>>;
const ll MOD = 998244353;
const ll INF = (ll)1e16;
const int MAX = 500000;
const ld PI = (acos(-1));
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
ld rad(ld a) {return a * PI / 180.0;}
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};//2次元グリッド上のx軸方向
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};//2次元グリッド上のy軸方向
template<class T> void rm(vector<T> &vec) {vec.erase(unique(vec.begin(), vec.end()), vec.end());}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
 
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

template <typename T>
struct BIT {
    int n;          // 配列の要素数(数列の要素数+1)
    vector<T> bit;  // データの格納先
    BIT(int n_) : n(n_ + 1), bit(n, 0) {}
    void add(int i, T x) {
        for (int idx = i; idx < n; idx += (idx & -idx)) {
            bit[idx] += x;
        }
    }
    T sum(int i) {
        T s(0);
        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
            s += bit[idx];
        }
        return s;
    }
};


 
vector<pair<ll, ll>> factorize(ll N) {
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
 
ll mod(ll val,ll mod = MOD) {
  ll res = val % mod;
  if (res < 0) res += mod;
  return res;
}
 
char upper(char c){
    if('a' <= c && c <= 'z'){
        c = c - ('a' - 'A');
    }
    return c;
}
char lower(char c){
    if('A' <= c && c <= 'Z'){
        c = c + ('a' - 'A');
    }
    return c;
}

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll Expo(ll N,ll K,ll md = MOD) {
    N %= md;
    if (K == 0) {
        return 1;
    }
    ll Kc = K,rui = N,ans = 1;
    while(Kc) {
        if (Kc % 2) {
            ans *= rui;
            ans %= md;
        }
        rui *= rui;
        rui %= md;
        Kc >>= 1;
    }
    return ans;
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x); // 再帰的に解く
    y -= a / b * x;
    return d;
}

int op(int a,int b) {
    return a + b;
}

int e() {
    return (int)0;
}

template <class S, S (*op)(S, S), S (*e)()> struct segtree {
  public:
    int ceil_pow2(int n) {
        int x = 0;
        while ((1U << x) < (unsigned int)(n)) x++;
        return x;
    }
    segtree() : segtree(0) {}
    segtree(int n) : segtree(vector<S>(n, e())) {}
    segtree(const vector<S>& v) : _n(int(v.size())) {
        log = ceil_pow2(_n);
        size = 1 << log;
        d = vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;

        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }

    S all_prod() { return d[1]; }

    template <bool (*f)(S)> int max_right(int l) {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*f)(S)> int min_left(int r) {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

  private:
    int _n, size, log;
    vector<S> d;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};



template<class T>
constexpr auto unit() -> enable_if_t<is_integral<T>::value, T> {
	return 1;
}
template<class T>
constexpr auto unit() -> enable_if_t<is_floating_point<T>::value, T> {
	return 1e-14;
}

template<class T> T sqroot(T Ex) {
    T l = 0,r = min(Ex,(T)(1e9));
    while (r - l > unit<T>()) {
        T val = (l + r) / 2;
        if (val * val > Ex) r = val;
        else l = val;
    }
    return l;//Ex以下のT型の平方根
}

#define Sugsugar cin.tie(0);ios::sync_with_stdio(false)

template<class T> void sitpress(vector<T> &vec) {
    vector<T> array = vec;
    sort(array.begin(),array.end());
    rm(array);
    for (int i = 0; i < vec.size(); i++) {
        int l = -1,r = array.size();
        while (r - l > 1) {
            int mid = (l + r) / 2;
            if (array.at(mid) >= vec.at(i)) r = mid;
            else l = mid;
        }
        vec.at(i) = r;
    }
}

template<class T> ll Rolling(vector<T> Girl) {
    BIT<int> RG(Girl.size());
    int si = Girl.size();
    ll gl = 0;
    sitpress(Girl);
    for (int i = 0; i < si; i++) {
        Girl.at(i)++;
        gl += RG.sum(si) - RG.sum(Girl.at(i));
        RG.add(Girl.at(i),1);
    }
    return gl;
}

vll mat(vll a, vll b) {
    assert(a.at(0).size() == b.size());
    int l = a.size(),m = b.size(),n = b.at(0).size();
    vll c(l,vector<ll>(n,0));
    for (int i = 0; i < l; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < m; k++) {
                c.at(i).at(j) += a.at(i).at(k) * b.at(k).at(j) % MOD;
                c.at(i).at(j) %= MOD;
            }
        }
    }
    return c;
}

vll Matpower(vll a,ll bit) { //この行列は正方行列のみ
    vll ans(a.size(),vector<ll>(a.size()));
    bool hoge = true;
    for (int i = 0; i <= 62; i++) {
        if ((bit >> i) & 1) {
            if (hoge) {
                ans = a;
                hoge = false;
            }
            else {
                ans = mat(ans,a);
            }
        }
        a = mat(a,a);
    }
    return ans;
}

vector<ll> OneHeart(vector<ll> X,vector<ll> Y) {
    ll denom = 2 * (X[2] * Y[1] - X[1] * Y[2] + X[0] * Y[2] - X[2] * Y[0] + X[1] * Y[0] - X[0] * Y[1]);
    ll molec = Y[0] * (X[2] * X[2] + Y[2] * Y[2] - X[1] * X[1] - Y[1] * Y[1]);
    molec += Y[1] * (X[0] * X[0] + Y[0] * Y[0] - X[2] * X[2] - Y[2] * Y[2]);
    molec += Y[2] * (X[1] * X[1] + Y[1] * Y[1] - X[0] * X[0] - Y[0] * Y[0]);
    if (denom == 0) {
        vector<ll> Cor{-INF,-INF};
        return Cor;
    }
    molec *= -1;
    if (denom * molec >= 0) {
        chmax(denom,-denom);
        chmax(molec,-molec);
    }
    else {
        chmax(denom,-denom);
        chmin(molec,-molec);
    }
    vector<ll> Cor{molec,denom};
    return Cor;
}

vector<vector<ll>> OutHeart(vector<ll> X, vector<ll> Y){
    vector<vector<ll>> OutH(2,vector<ll>(2));
    OutH.at(0) = OneHeart(X,Y);
    OutH.at(1) = OneHeart(Y,X);
    return OutH;
}

struct edge {ll to,cost,roop;};
template<class T> using Graph = vector<vector<T>>;

signed main(){
    Sugsugar;
    ll N;
    cin >> N;
    vector<ll> lis;
    vector<bool> A(N,false);
    for (ll i = 2; i < N; i++) {
        if (A.at(i)) continue;
        lis.push_back(i);
        for (ll j = i * i; j < N; j += i) A.at(j) = true;
    }
    ll sum = 1;
    for (int i = 0; i < lis.size(); i++) {
        ll hoge = N,rui = 0,huga = 1;
        while (hoge % lis.at(i) == 0 && hoge >= lis.at(i)) {
            hoge /= lis.at(i);
            rui += 2;
        }
        if (hoge == 1) {
            hoge *= lis.at(i);
            rui -= 2;
        }
        while (huga * lis.at(i) < hoge) {
            huga *= lis.at(i);
            rui++;
        }
        sum *= Expo(lis.at(i),rui,MOD);
        sum %= MOD;
    }
    cout << sum << endl;
    return 0;
}
0