結果

問題 No.1529 Constant Lcm
ユーザー V_MelvilleV_Melville
提出日時 2021-06-25 16:51:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,690 bytes
コンパイル時間 2,339 ms
コンパイル使用メモリ 214,040 KB
実行使用メモリ 813,892 KB
最終ジャッジ日時 2023-09-07 13:37:40
合計ジャッジ時間 8,748 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
7,444 KB
testcase_01 RE -
testcase_02 AC 11 ms
7,384 KB
testcase_03 AC 11 ms
7,332 KB
testcase_04 AC 10 ms
7,436 KB
testcase_05 AC 11 ms
7,584 KB
testcase_06 AC 10 ms
7,588 KB
testcase_07 AC 11 ms
7,336 KB
testcase_08 AC 11 ms
7,576 KB
testcase_09 AC 11 ms
7,588 KB
testcase_10 RE -
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fi first
#define se second

using std::cin;
using std::cout;
using std::max;
using std::map;
using std::vector;
using ll = long long;
using P = std::pair<int, int>;

const int N = 1000005;

const int mod = 1000000007;
struct mint {
  ll x; 
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n = 1): n(n), f(n + 1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; ++i) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x; }
    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.size() == 0) return {};
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl) {
            if (res.back().fi == p) {
                res.back().se++;
            }
            else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

int main() {
    Sieve sieve(1e6);
    int n;
    cin >> n;

    vector<ll> a(n - 1);
    rep(i, n - 1) a[i] = 1ll * (i + 1) * (n - i - 1);

    map<int, int> mp;
    rep(i, n - 1) {
        auto f = sieve.factor(a[i]);
        for (auto p : f) {
            mp[p.fi] = max(mp[p.fi], p.se);
        }
    }

    mint lcm = 1;
    for (auto p : mp) {
        rep(i, p.se) {
            lcm *= p.fi;
        } 
    }

    cout << lcm.x << '\n';

    return 0;
}
0