結果

問題 No.2365 Present of good number
ユーザー milanis48663220milanis48663220
提出日時 2023-06-30 21:56:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 3,078 bytes
コンパイル時間 1,413 ms
コンパイル使用メモリ 130,936 KB
実行使用メモリ 10,408 KB
最終ジャッジ日時 2023-09-21 15:51:14
合計ジャッジ時間 4,881 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
10,192 KB
testcase_01 AC 42 ms
10,140 KB
testcase_02 AC 42 ms
10,240 KB
testcase_03 AC 41 ms
10,184 KB
testcase_04 AC 42 ms
10,408 KB
testcase_05 AC 42 ms
10,404 KB
testcase_06 AC 41 ms
10,272 KB
testcase_07 AC 40 ms
10,252 KB
testcase_08 AC 42 ms
10,260 KB
testcase_09 AC 41 ms
10,408 KB
testcase_10 AC 41 ms
10,140 KB
testcase_11 AC 42 ms
10,188 KB
testcase_12 AC 42 ms
10,336 KB
testcase_13 AC 43 ms
10,276 KB
testcase_14 AC 40 ms
10,188 KB
testcase_15 AC 39 ms
10,196 KB
testcase_16 AC 40 ms
10,232 KB
testcase_17 AC 39 ms
10,236 KB
testcase_18 AC 39 ms
10,128 KB
testcase_19 AC 42 ms
10,136 KB
testcase_20 AC 40 ms
10,236 KB
testcase_21 AC 40 ms
10,308 KB
testcase_22 AC 39 ms
10,272 KB
testcase_23 AC 38 ms
10,136 KB
testcase_24 AC 43 ms
10,196 KB
testcase_25 AC 41 ms
10,188 KB
testcase_26 AC 41 ms
10,236 KB
testcase_27 AC 41 ms
10,284 KB
testcase_28 AC 43 ms
10,184 KB
testcase_29 AC 42 ms
10,408 KB
testcase_30 AC 42 ms
10,180 KB
testcase_31 AC 43 ms
10,140 KB
testcase_32 AC 42 ms
10,280 KB
testcase_33 AC 41 ms
10,308 KB
testcase_34 AC 41 ms
10,180 KB
testcase_35 AC 40 ms
10,276 KB
testcase_36 AC 42 ms
10,408 KB
testcase_37 AC 42 ms
10,188 KB
testcase_38 AC 41 ms
10,144 KB
testcase_39 AC 41 ms
10,180 KB
testcase_40 AC 44 ms
10,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using mint = atcoder::modint1000000007;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}


class Eratosthenes{
    public:
    int m;
    vector<bool> is_prime;
    vector<int> primes;
    Eratosthenes(int m_){
        m = m_;
        init();
    }
    private:
    void init(){
        is_prime.assign(m+1, true);
        is_prime[0] = false, is_prime[1] = false;
        for(int i = 2; i <= m; i++){
            if(is_prime[i]){
                primes.push_back(i);
                for(int j = 2; i*j <= m; j++) is_prime[i*j] = false;
            }
        }
    }
};

const int N = 100000;
using P = pair<int, int>;
Eratosthenes et(N);
vector<P> facs[N+1];

void init(){
    vector<int> v(N+1);
    iota(v.begin(), v.end(), 0);
    for(int p = 2; p <= N; p++){
        for(int i = 1; i*p <= N; i++){
            if(v[i*p]%p != 0) continue;
            int cnt = 0;
            while(v[i*p]%p == 0){
                v[i*p] /= p;
                cnt++;
            }
            facs[i*p].push_back({p, cnt});
        }
    }
}

ll mod_pow(ll a, ll n, ll mod) {
    ll ans = 1;
    while (n > 0) {
        if (n&1) ans = (ans*a)%mod;
        a = (a*a)% mod;
        n >>= 1;
    }
    return ans;
}


mint f(int n, ll k){
    if(k == 0) return mint(n);
    if(n == 2){
        ll cycle = k/2;
        int rem = k%2;
        int r = mod_pow(2, cycle, mint::mod()-1);
        if(rem == 0){
            return mint(2).pow(r);
        }else{
            return mint(3).pow(r);
        }
    }
    mint ans = 1;
    for(auto [p, cnt]: facs[n]){
        for(auto [q, c]: facs[p+1]){
            ans *= f(q, k-1).pow(cnt*c);
        }
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    int n; cin >> n;
    ll k; cin >> k;
    cout << f(n, k) << endl;
}
0