結果

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

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<1000000007>;

vector<int> pf(int n){
    vector<int> res;
    for(int p=2; p*p<=n; p++){
        while(n%p == 0){
            res.push_back(p);
            n /= p;
        }
    }
    if(n != 1) res.push_back(n);
    return res;
}

int main(){
    i64 N, K; cin >> N >> K;
    map<int, i64> mp;
    for(int x : pf(N)) mp[x] += 1;
    while(K){
        if(mp.size() == mp.count(2) + mp.count(3)) break;
        K--;
        map<int, i64> buf;
        for(auto [p,c] : mp) for(int q : pf(p+1)) buf[q] += c;
        for(auto& q : buf) q.second %= 1000000006;
        swap(mp, buf);
    }
    if(K == 0){
        Modint ans = 1;
        for(auto [p,c] : mp) ans *= Modint(p).pow(c);
        cout << ans.val();
    }
    else{
        i64 q = atcoder::static_modint<1000000006>(2).pow(K/2).val();
        K %= 2;
        if(K % 2 == 0){
            auto q2 = Modint(2).pow(mp[2]).pow(q);
            auto q3 = Modint(3).pow(mp[3]).pow(q);
            cout << (q2 * q3).val() << endl;
        }
        else{
            auto q2 = Modint(2).pow(mp[3]).pow(q*2);
            auto q3 = Modint(3).pow(mp[2]).pow(q);
            cout << (q2 * q3).val() << endl;
        }
    }
    return 0;
}
0