結果
問題 | No.2365 Present of good number |
ユーザー | erbowl |
提出日時 | 2023-07-02 11:17:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 7,104 bytes |
コンパイル時間 | 3,190 ms |
コンパイル使用メモリ | 232,436 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-16 07:15:48 |
合計ジャッジ時間 | 4,134 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 9 ms
5,376 KB |
testcase_03 | AC | 9 ms
5,376 KB |
testcase_04 | AC | 9 ms
5,376 KB |
testcase_05 | AC | 9 ms
5,376 KB |
testcase_06 | AC | 5 ms
5,376 KB |
testcase_07 | AC | 7 ms
5,376 KB |
testcase_08 | AC | 5 ms
5,376 KB |
testcase_09 | AC | 4 ms
5,376 KB |
testcase_10 | AC | 9 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 5 ms
5,376 KB |
testcase_13 | AC | 8 ms
5,376 KB |
testcase_14 | AC | 7 ms
5,376 KB |
testcase_15 | AC | 4 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 3 ms
5,376 KB |
testcase_23 | AC | 7 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 4 ms
5,376 KB |
testcase_26 | AC | 7 ms
5,376 KB |
testcase_27 | AC | 5 ms
5,376 KB |
testcase_28 | AC | 3 ms
5,376 KB |
testcase_29 | AC | 8 ms
5,376 KB |
testcase_30 | AC | 4 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 8 ms
5,376 KB |
testcase_37 | AC | 9 ms
5,376 KB |
testcase_38 | AC | 6 ms
5,376 KB |
testcase_39 | AC | 6 ms
5,376 KB |
testcase_40 | AC | 9 ms
5,376 KB |
ソースコード
typedef long long ll; typedef long double ld; #include <bits/stdc++.h> using namespace std; #define int long long struct Eratos { vector<int> primes; vector<bool> isprime; vector<int> mebius; vector<int> min_factor; Eratos(int MAX) : primes(), isprime(MAX+1, true), mebius(MAX+1, 1), min_factor(MAX+1, -1) { isprime[0] = isprime[1] = false; min_factor[0] = 0, min_factor[1] = 1; for (int i = 2; i <= MAX; ++i) { if (!isprime[i]) continue; primes.push_back(i); mebius[i] = -1; min_factor[i] = i; for (int j = i*2; j <= MAX; j += i) { isprime[j] = false; if ((j / i) % i == 0) mebius[j] = 0; else mebius[j] = -mebius[j]; if (min_factor[j] == -1) min_factor[j] = i; } } } // prime factorization vector<pair<int,int>> prime_factors(int n) { vector<pair<int,int> > res; while (n != 1) { int prime = min_factor[n]; int exp = 0; while (min_factor[n] == prime) { ++exp; n /= prime; } res.push_back(make_pair(prime, exp)); } return res; } // enumerate divisors vector<int> divisors(int n) { vector<int> res({1}); auto pf = prime_factors(n); for (auto p : pf) { int n = (int)res.size(); for (int i = 0; i < n; ++i) { int v = 1; for (int j = 0; j < p.second; ++j) { v *= p.first; res.push_back(res[i] * v); } } } return res; } }; const long long MOD = 1e9+7; long long modinv(long long a, long long mod) { 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; } // matrix template<int MOD> struct Matrix { vector<vector<long long> > val; Matrix(int n, int m, long long x = 0) : val(n, vector<long long>(m, x)) {} void init(int n, int m, long long x = 0) {val.assign(n, vector<long long>(m, x));} size_t size() const {return val.size();} inline vector<long long>& operator [] (int i) {return val[i];} }; template<int MOD> ostream& operator << (ostream& s, Matrix<MOD> A) { s << endl; for (int i = 0; i < A.size(); ++i) { for (int j = 0; j < A[i].size(); ++j) { s << A[i][j] << ", "; } s << endl; } return s; } template<int MOD> Matrix<MOD> operator * (Matrix<MOD> A, Matrix<MOD> B) { Matrix<MOD> R(A.size(), B[0].size()); for (int i = 0; i < A.size(); ++i) for (int j = 0; j < B[0].size(); ++j) for (int k = 0; k < B.size(); ++k) R[i][j] = (R[i][j] + A[i][k] * B[k][j] % MOD) % MOD; return R; } template<int MOD> Matrix<MOD> pow(Matrix<MOD> A, long long n) { Matrix<MOD> R(A.size(), A.size()); for (int i = 0; i < A.size(); ++i) R[i][i] = 1; while (n > 0) { if (n & 1) R = R * A; A = A * A; n >>= 1; } return R; } // modint template<int MOD> struct Fp { // inner value long long val; // constructor constexpr Fp() noexcept : val(0) { } constexpr Fp(long long v) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr long long get() const noexcept { return val; } constexpr int get_mod() const noexcept { return MOD; } // arithmetic operators constexpr Fp operator - () const noexcept { return val ? MOD - val : 0; } constexpr Fp operator + (const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator - (const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator * (const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator / (const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp& operator += (const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp &r) noexcept { long long a = r.val, 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); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr Fp pow(long long n) const noexcept { Fp res(1), mul(*this); while (n > 0) { if (n & 1) res *= mul; mul *= mul; n >>= 1; } return res; } constexpr Fp inv() const noexcept { Fp res(1), div(*this); return res / div; } // other operators constexpr bool operator == (const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator != (const Fp &r) const noexcept { return this->val != r.val; } friend constexpr istream& operator >> (istream &is, Fp<MOD> &x) noexcept { is >> x.val; x.val %= MOD; if (x.val < 0) x.val += MOD; return is; } friend constexpr ostream& operator << (ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &r, long long n) noexcept { return r.pow(n); } friend constexpr Fp<MOD> modinv(const Fp<MOD> &r) noexcept { return r.inv(); } }; signed main(){ using mint = Fp<MOD>; ll n,k; std::cin >> n>>k; Eratos era(n+10); set<ll> p; queue<ll> q; for (auto e : era.prime_factors(n)) { q.push(e.first); p.insert(e.first); } while(q.size()){ auto now = q.front();q.pop(); auto es = era.prime_factors(now); for (auto e : es) { for (auto ee : era.prime_factors(e.first+1)) { if(p.find(ee.first)==p.end()){ p.insert(ee.first); q.push(ee.first); } } } } Matrix<MOD-1> m(p.size(), p.size(), 0); unordered_map<ll,ll> pind; ll ind = 0; for (auto e : p) { pind[e] = ind; ind++; } for (auto e : p) { for (auto ee : era.prime_factors(e+1)) { m[pind[e]][pind[ee.first]] += ee.second; } } Matrix<MOD-1> c(1, p.size(), 0); for (auto e : era.prime_factors(n)) { c[0][pind[e.first]] += e.second; } auto res = c*pow(m,k); mint ans = 1; for (auto e : p) { ans *= mint(e).pow(res[0][pind[e]]); } std::cout << ans << std::endl; }