結果

問題 No.2365 Present of good number
ユーザー 👑 eoeoeoeo
提出日時 2023-06-30 23:15:49
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 9,548 bytes
コンパイル時間 3,980 ms
コンパイル使用メモリ 280,140 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 17:33:22
合計ジャッジ時間 5,826 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef MY_DEBUG
#define dbg(...) debug_out(__VA_ARGS__)
#define dbgn(var) debug_out(#var, "=", var)
#else
#define dbg(...)
#define dbgn(...)
#endif
void debug_out();
template <class Head, class... Tail> void debug_out(Head, Tail...);
template <class T> bool chmax(T&, const T&);
template <class T> bool chmin(T&, const T&);
template <class T> T pwr(T, ll);
template <class T> T squ(T x) { return x * x; }
ll fact(ll);
ll comb(ll, ll);
ll ctoll(char);
char lltoc(ll);
bool flg(ll b, ll i) { return ((b) >> (i)) & 1LL; }  // flg(0b010, 1LL) -> true
const ll LINF = (ll)1e18 + 7;
const double EPS = 1e-9;
const int MAX_DUBUG_SIZE = 10;

constexpr uint32_t totient(uint32_t x) {
    uint32_t ans = x;
    for (uint32_t i = 2; i * i <= x; i++)
        if (x % i == 0) {
            ans /= i;
            ans *= i - 1;
            do x /= i;
            while (x % i == 0);
        }
    if (x != 1) {
        ans /= x;
        ans *= x - 1;
    }
    return ans;
}
template <uint32_t P> struct Modint {
    static_assert(P < 0x80000000, "P must be smaller than 2^31");
    uint32_t a;
    Modint<totient(P)> b;

private:
    static uint32_t mod(uint64_t x) {
        if (x < P * 2) return uint32_t(x);
        return uint32_t(x % P) + P;
    }
    static uint32_t mul(uint32_t a, uint32_t b) { return mod(uint64_t(a) * b); }
    static uint32_t pow(uint32_t a, uint32_t b) {
        uint32_t ans = 1;
        while (b) {
            if (b & 1) ans = mul(ans, a);
            a = mul(a, a);
            b >>= 1;
        }
        return ans;
    }

public:
    Modint(uint64_t x) : a(mod(x)), b(x) {}
    Modint(uint32_t a, Modint<totient(P)> b) : a(a), b(b) {}
    uint32_t val() const {
        if (a < P) return a;
        return a - P;
    }
    Modint& operator*=(const Modint& other) {
        a = mul(a, other.a);
        b *= other.b;
        return *this;
    }
    Modint operator*(const Modint& other) const { return Modint(*this) *= other; }
    Modint& operator+=(const Modint& other) {
        a += other.a;
        if (a >= P * 2) a -= P;
        if (a >= P * 2) a -= P;
        b += other.b;
        return *this;
    }
    Modint operator+(const Modint& other) const { return Modint(*this) += other; }
    Modint pow(const Modint& other) const { return {pow(a, other.b.a), b.pow(other.b)}; };
};
template <> struct Modint<1> {
    uint32_t a;
    Modint(uint64_t x) : a(bool(x)) {}
    uint32_t val() const { return 0; }
    Modint& operator*=(const Modint& other) {
        a &= other.a;
        return *this;
    }
    Modint operator*(const Modint& other) const { return Modint(*this) *= other; }
    Modint& operator+=(const Modint& other) {
        a |= other.a;
        return *this;
    }
    Modint operator+(const Modint& other) const { return Modint(*this) += other; }
    Modint pow(const Modint& other) const { return {a || !other.a}; }
};

using mint = Modint<1000000007>;

// 素因数分解 計算量O(√N)
map<ll, ll> prime_factor(ll N) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= N; i++) {
        while (N % i == 0) {
            res[i]++;
            N /= i;
        }
    }

    if (N != 1) {  // N が素数の場合
        res[N] = 1;
    }

    return res;
}

bool exist_only_2and3(map<ll, ll> mp) {
    if (mp.size() > 2) return false;
    for (auto&& [x, y] : mp) {
        if (x != 2 and x != 3) return false;
    }
    return true;
}

mint fk(ll x, ll k) {
    auto pf = prime_factor(x);

    while (!exist_only_2and3(pf) and k > 0) {
        map<ll, ll> tmp;
        for (auto&& [x, y] : pf) {
            auto pf_x = prime_factor(x + 1);
            for (auto&& [xx, yy] : pf_x) {
                tmp[xx] += yy;
            }
        }
        pf = tmp;
        k--;
    }

    dbg(k);
    for (auto&& [x, y] : pf) {
        dbg(x, y);
    }

    mint res = 1;

    if (k == 0) {
        for (auto&& [x, y] : pf) {
            res *= mint(x).pow(y);
        }
        return res;
    }
    else {
        ll pw = k / 2;
        ll rm = k % 2;
        mint pwr2 = mint(pf[2]) * mint(2).pow(pw);
        mint pwr3 = mint(pf[3]) * mint(2).pow(pw);

        dbg(pw, rm, pwr2.val(), pwr3.val());

        if (rm == 0) {
            res *= mint(2).pow(pwr2);
            res *= mint(3).pow(pwr3);
        }
        else {
            res *= mint(3).pow(pwr2);
            res *= mint(2).pow(pwr3 * 2);
        }

        return res;
    }
}

void solve([[maybe_unused]] int test) {
    ll n, k;
    cin >> n >> k;

    mint ans = 1;
    auto pf = prime_factor(n);
    for (auto&& [x, y] : pf) {
        mint tmp = fk(x, k).pow(y);
        ans *= tmp;
    }

    cout << ans.val() << endl;
}

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12);

    int testcase_size = 1;
    // cin >> testcase_size;

    for (int _t = 0; _t < testcase_size; _t++) {
        solve(_t);
    }

    // dbg(fk(2, 4).val());
}

/*



























-----------------------------------MY_FUNCTIONS------------------------------------ */
template <class First, class Second> ostream& operator<<(ostream& os, const pair<First, Second>& pp) {
    return os << "{" << pp.first << "," << pp.second << "}";
}

template <class T> ostream& operator<<(ostream& os, const vector<T>& V) {
    if (V.empty()) return os << "[]";
    os << "[";
    for (ll i = 0; i < (ll)V.size(); i++) {
        os << V[i] << (i == int(V.size() - 1) ? "]" : ",");
    }
    return os;
}

template <class T> ostream& operator<<(ostream& os, const vector<vector<T>>& VV) {
    if (VV.empty()) return os << "[[]]";
    os << "[\n";
    for (auto&& V : VV) {
        os << V << "\n";
    }
    os << "]";
    return os;
}

template <class T> ostream& operator<<(ostream& os, const vector<vector<vector<T>>>& VVV) {
    if (VVV.empty()) return os << "[[[]]]";
    os << "["
       << "\n";
    int cnt = 0;
    for (auto&& VV : VVV) {
        os << cnt++ << VV << "\n\n";
    }
    os << "]";
    return os;
}

template <class T> ostream& operator<<(ostream& os, const set<T>& SS) {
    if (SS.empty()) return os << "[]";
    os << "[";
    auto ii = SS.begin();
    for (; ii != SS.end(); ii++) os << *ii << (ii == prev(SS.end()) ? "]" : ",");
    return os;
}

template <class Key, class Tp> ostream& operator<<(ostream& os, const map<Key, Tp>& MM) {
    if (MM.empty()) return os << "[{:}]";
    os << "[";
    auto ii = MM.begin();
    for (; ii != MM.end(); ii++)
        os << "{" << ii->first << ":" << ii->second << "}" << (ii == prev(MM.end()) ? "]" : ",");
    return os;
}

void debug_out() { cerr << endl; }

void debug_out_vl(vector<ll> V) {
    const int MAX_SIZE = min((int)V.size(), MAX_DUBUG_SIZE);

    cerr << "\033[33m";
    if (V.empty()) {
        cerr << "[]" << endl;
        return;
    }
    cerr << "[";
    for (int i = 0; i < MAX_SIZE; i++) {
        if (V[i] == LINF)
            cerr << "INF";
        else
            cerr << V[i];

        if (i == (int)V.size() - 1)
            cerr << "]\n";
        else if (i == MAX_DUBUG_SIZE - 1)
            cerr << ",...\n";
        else
            cerr << ",";
    }
    return;
}

void debug_out_vvl(vector<vector<ll>> VV) {
    cerr << "\033[33m";
    if (VV.empty()) {
        cerr << "[[]]" << endl;
        return;
    }
    cerr << "[\n";

    int MAX_ROW = min((int)VV.size(), MAX_DUBUG_SIZE);
    for (int i = 0; i < MAX_ROW; i++) {
        const int MAX_COLUMN = min((int)VV[i].size(), MAX_DUBUG_SIZE);
        if (VV[i].empty()) {
            cerr << "[]" << endl;
            continue;
        }
        cerr << "[";
        for (int j = 0; j < MAX_COLUMN; j++) {
            if (VV[i][j] == LINF)
                cerr << "INF";
            else
                cerr << VV[i][j];

            if (j == (int)VV[i].size() - 1)
                cerr << "]\n";
            else if (j == MAX_DUBUG_SIZE - 1)
                cerr << ",...\n";
            else
                cerr << ",";
        }

        if (i != (int)VV.size() - 1 and i == MAX_DUBUG_SIZE - 1) {
            cerr << ":\n:\033[m\n";
            return;
        }
    }

    cerr << "]\033[m\n";
    return;
}

template <class Head, class... Tail> void debug_out(Head H, Tail... T) {
    if constexpr (std::is_same_v<Head, vector<ll>>) {
        debug_out_vl(H);
    }
    else if constexpr (std::is_same_v<Head, vector<vector<ll>>>) {
        debug_out_vvl(H);
    }
    else {
        cerr << "\033[33m" << H << "\033[m ";
    }

    debug_out(T...);
}

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

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

template <class T> T pwr(T x, ll n) {
    T res = 1;
    for (int i = 0; i < n; i++) {
        res *= x;
    }
    return res;
}

ll fact(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) res *= i;
    return res;
}

ll comb(ll n, ll r) {  // comb(60, 30)までオーバーフローなし
    ll res = 1;
    for (int i = 1; i <= r; i++) {
        res *= n--;
        res /= i;
    }
    return res;
}

ll ctoll(char c) {
    if (c < '0' or '9' < c) {
        cerr << "\n\033[33m ctoll に '0'~'9' 以外の文字が入りました.\033[m\n" << endl;
    }
    return ll(c - '0');
}

char lltoc(ll n) {
    if (n < 0 or 9 < n) {
        cerr << "\n\033[33m lltoc に 0 ~ 9 以外の数字が入りました.\033[m\n" << endl;
    }
    return char(n + '0');
}
0