結果

問題 No.2365 Present of good number
ユーザー t98slidert98slider
提出日時 2023-06-30 22:06:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 5,697 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 185,600 KB
実行使用メモリ 15,676 KB
最終ジャッジ日時 2023-09-21 16:07:43
合計ジャッジ時間 4,206 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 47 ms
15,600 KB
testcase_03 AC 38 ms
13,540 KB
testcase_04 AC 49 ms
15,676 KB
testcase_05 AC 50 ms
15,652 KB
testcase_06 AC 20 ms
8,504 KB
testcase_07 AC 26 ms
10,464 KB
testcase_08 AC 19 ms
8,524 KB
testcase_09 AC 16 ms
7,868 KB
testcase_10 AC 41 ms
13,728 KB
testcase_11 AC 6 ms
4,688 KB
testcase_12 AC 22 ms
9,048 KB
testcase_13 AC 57 ms
13,540 KB
testcase_14 AC 32 ms
11,500 KB
testcase_15 AC 12 ms
6,224 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 11 ms
5,944 KB
testcase_23 AC 33 ms
11,520 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 18 ms
7,728 KB
testcase_26 AC 28 ms
10,900 KB
testcase_27 AC 22 ms
9,152 KB
testcase_28 AC 7 ms
4,808 KB
testcase_29 AC 37 ms
12,408 KB
testcase_30 AC 9 ms
5,520 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 35 ms
12,288 KB
testcase_37 AC 45 ms
14,848 KB
testcase_38 AC 25 ms
10,676 KB
testcase_39 AC 25 ms
10,648 KB
testcase_40 AC 42 ms
14,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}

template<const unsigned int MOD> struct prime_modint {
    using mint = prime_modint;
    unsigned int v;
    prime_modint() : v(0) {}
    prime_modint(unsigned int a) { a %= MOD; v = a; }
    prime_modint(unsigned long long a) { a %= MOD; v = a; }
    prime_modint(int a) { a %= (int)(MOD); if(a < 0)a += MOD; v = a; }
    prime_modint(long long a) { a %= (int)(MOD); if(a < 0)a += MOD; v = a; }
    static constexpr int mod() { return MOD; }
    mint& operator++() {v++; if(v == MOD)v = 0; return *this;}
    mint& operator--() {if(v == 0)v = MOD; v--; return *this;}
    mint operator++(int) { mint result = *this; ++*this; return result; }
    mint operator--(int) { mint result = *this; --*this; return result; }
    mint& operator+=(const mint& rhs) { v += rhs.v; if(v >= MOD) v -= MOD; return *this; }
    mint& operator-=(const mint& rhs) { if(v < rhs.v) v += MOD; v -= rhs.v; return *this; }
    mint& operator*=(const mint& rhs) {
        v = (unsigned int)((unsigned long long)(v) * rhs.v % MOD);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    mint pow(long long n) const {
        assert(0 <= n);
        mint r = 1, x = *this;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const { assert(v); return pow(MOD - 2); }
    friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; }
    friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; }
    friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; }
    friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; }
    friend bool operator==(const mint& lhs, const mint& rhs) { return (lhs.v == rhs.v); }
    friend bool operator!=(const mint& lhs, const mint& rhs) { return (lhs.v != rhs.v); }
    friend std::ostream& operator << (std::ostream &os, const mint& rhs) noexcept { return os << rhs.v; }
};
using mint = prime_modint<1000000007>;
using mint2 = prime_modint<1000000006>;
//using mint = prime_modint<998244353>;

struct osa_k{
    int n;
    vector<int> osak_calc;
    osa_k(int n = 1000001) {
        osak_calc.resize(n, -1);
        int d;
        for(int i = 2; i < n; i += 2) osak_calc[i] = 2;
        for(int i = 3; i < n; i += 2){
            if(osak_calc[i] != -1)continue;
            d = i << 1;
            for(int j = i; j < n; j += d){
                if(osak_calc[j] != -1)continue;
                osak_calc[j] = i;
            }
        }
    }
    bool is_Prime(int x){
        return (osak_calc[x] == x);
    }
    vector<pair<int, int>> prime_factor(int x){
        vector<pair<int, int>> ret;
        if(x <= 1)return ret;
        ret.emplace_back(osak_calc[x], 1);
        x /= osak_calc[x];
        while(osak_calc[x] != -1){
            if(osak_calc[x] == ret.back().first){
                ret.back().second++;
            }else{
                ret.emplace_back(osak_calc[x], 1);
            }
            x /= osak_calc[x];
        }
        return ret;
    }
    //最小公倍数の数列を返す
    vector<pair<int,int>> array_lcm(vector<int> a){
        map<int,int> Map;
        for(int i = 0; i < (int)a.size(); i++){
            vector<pair<int,int>> b = prime_factor(a[i]);
            for(int j=0;j<(int)b.size();j++){
                if(Map.count(b[j].first)){
                    if(b[j].second>Map[b[j].first])Map[b[j].first]=b[j].second;
                }else{
                    Map[b[j].first]=b[j].second;
                }
            }
        }
        vector<pair<int,int>> ret;
        for(auto v:Map)ret.emplace_back(v.first,v.second);
        return ret;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    int m = 2 * n;
    vector<vector<int>> tb(m + 1);
    vector<int> c(m + 1);
    iota(c.begin(), c.end(), 0);
    for(int i = 2; i <= m; i++){
        if(c[i] == 1) continue;
        const int v = c[i];
        for(int j = i; j <= m; j += i){
            tb[j].emplace_back(v);
            c[j] /= v;
        }
    }
    map<int, mint2> mp;
    int mx = -1;
    for(auto &&v : tb[n]){
        mp[v]++;
        mx = max(mx, v);
    }
    while(k && mx >= 5){
        k--;
        int mx2 = -1;
        map<int, mint2> mp2;
        for(auto &&pa : mp){
            for(auto &&v : tb[pa.first + 1]){
                mp2[v] += pa.second;
                mx2 = max(mx2, v);
            }
        }
        swap(mp, mp2);
        swap(mx, mx2);
    }
    mint ans = 1;
    if(k == 0){
        for(auto &&pa : mp){
            ans *= mint(pa.first).pow(pa.second.v);
        }
    }else if(k % 2 == 0){
        if(mp[2].v >= 1){
            ans *= mint(2).pow((mp[2] * mint2(2).pow(k / 2)).v);
        }
        if(mp[3].v >= 1){
            ans *= mint(3).pow((mp[3] * mint2(2).pow(k / 2)).v);
        }
    }else{
        if(mp[2].v >= 1){
            ans *= mint(3).pow((mp[2] * mint2(2).pow(k / 2)).v);
        }
        if(mp[3].v >= 1){
            ans *= mint(2).pow((mp[3] * mint2(2).pow((k + 1) / 2)).v);
        }
    }
    cout << ans << '\n';
}
0