結果

問題 No.2365 Present of good number
ユーザー hourenhouren
提出日時 2023-06-30 22:31:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,614 bytes
コンパイル時間 1,786 ms
コンパイル使用メモリ 176,124 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 16:40:48
合計ジャッジ時間 3,322 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 1e9+7;
constexpr int INF = (1 << 30);
ll mpow(ll x, ll y, ll MOD_ = MOD){
    ll res = 1; x %= MOD_;
    while(y){
        if(y%2) res = res * x % MOD_;
        x = x * x % MOD_;
        y /= 2;
    }
    return res;
}
struct PrimeNumber{
    vector<int> _PN;
    vector<bool> _B;
    int n;
    PrimeNumber(int _n=0){
        init(_n);
    }
    void init(int _n){
        n = _n;
        _B.assign(n+1,true);
        _B[1] = false;
        for(int i=2;i<=n;i++){
            if(_B[i]){
                _PN.push_back(i);
                for(int j=2*i;j<=n;j+=i) _B[j] = false;
            }
        }
    }
    bool isprime_big(ll x){
        ll m = n;
        assert(x<=m*m);
        for(int &y:_PN){
            if(y*y>x) break;
            if(!(x%y)) return false;
        }
        return true;
    }
    bool isprime(ll x){
        assert(0<x);
        if(n<x) return isprime_big(x);
        return _B[x];
    }
    vector<int> pnlist(){ return _PN; };
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    PrimeNumber P(320);
    auto pn = P.pnlist();
    ll n,k;
    cin >> n >> k;
    ll t2 = 0, t3 = 0;
    vector<int> p;
    
    for(int d:pn){
        if(n==1) break;
        while(!(n%d)){
            if(d==2) t2++;
            else if(d==3) t3++;
            else p.push_back(d);
            n /= d;
        }
    }
    if(n>1) p.push_back(n);
    while(k){
        if(!p.size()) break;
        k--;
        t3 = t3 * 2 % (MOD-1);
        swap(t2,t3);
        vector<int> upd;
        for(int x:p){
            x++;
            for(int d:pn){
                if(x==1) break;
                while(!(x%d)){
                    if(d==2) t2++;
                    else if(d==3) t3++;
                    else upd.push_back(d);
                    x /= d;
                }
            }
            if(x>1) upd.push_back(x);
        }
        p = upd;
    }
    t2 = t2 * mpow(2,k/2,MOD-1) % (MOD-1);
    t3 = t3 * mpow(2,k/2,MOD-1) % (MOD-1);
    if(k&1){
        t3 = t3 * 2 % (MOD-1);
        swap(t2,t3);
    }
    ll ans = mpow(2,t2)*mpow(3,t3)%MOD;
    for(int x:p) ans = ans * (x) % MOD;
    cout << ans << '\n';
    return 0;
}
0