結果

問題 No.2365 Present of good number
ユーザー pointNpointN
提出日時 2023-06-30 22:18:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 2,557 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 149,892 KB
実行使用メモリ 42,252 KB
最終ジャッジ日時 2023-09-21 16:23:09
合計ジャッジ時間 11,173 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
42,108 KB
testcase_01 AC 162 ms
42,096 KB
testcase_02 AC 160 ms
42,108 KB
testcase_03 AC 166 ms
42,092 KB
testcase_04 AC 162 ms
42,108 KB
testcase_05 AC 159 ms
42,156 KB
testcase_06 AC 157 ms
42,160 KB
testcase_07 AC 149 ms
42,116 KB
testcase_08 AC 149 ms
41,972 KB
testcase_09 AC 154 ms
42,112 KB
testcase_10 AC 149 ms
42,112 KB
testcase_11 AC 150 ms
42,164 KB
testcase_12 AC 150 ms
42,248 KB
testcase_13 AC 151 ms
42,120 KB
testcase_14 AC 151 ms
42,160 KB
testcase_15 AC 155 ms
42,160 KB
testcase_16 AC 148 ms
42,252 KB
testcase_17 AC 148 ms
42,220 KB
testcase_18 AC 148 ms
42,148 KB
testcase_19 AC 146 ms
42,096 KB
testcase_20 AC 145 ms
42,112 KB
testcase_21 AC 151 ms
42,108 KB
testcase_22 AC 149 ms
42,156 KB
testcase_23 AC 149 ms
42,120 KB
testcase_24 AC 150 ms
42,156 KB
testcase_25 AC 151 ms
42,156 KB
testcase_26 AC 149 ms
42,224 KB
testcase_27 AC 150 ms
42,116 KB
testcase_28 AC 150 ms
41,928 KB
testcase_29 AC 147 ms
42,096 KB
testcase_30 AC 148 ms
42,096 KB
testcase_31 AC 149 ms
42,156 KB
testcase_32 AC 148 ms
42,200 KB
testcase_33 AC 147 ms
42,164 KB
testcase_34 AC 150 ms
42,112 KB
testcase_35 AC 145 ms
42,240 KB
testcase_36 AC 145 ms
42,196 KB
testcase_37 AC 145 ms
41,884 KB
testcase_38 AC 149 ms
42,160 KB
testcase_39 AC 147 ms
42,152 KB
testcase_40 AC 147 ms
42,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

const ll mod = 1000000007;

ll mpow(ll a, ll x){
  ll res = 1;
  while(x > 0){
    if(x & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    x >>= 1;
  }
  return res;
}

vector<vector<ll>> mul(vector<vector<ll>> A, vector<vector<ll>> B){
  vector<vector<ll>> C(2,vector<ll>(2,0));
  rep(i,2) rep(j,2) rep(k,2){
    C[i][j] += A[i][k] * B[k][j] % (mod-1);
    C[i][j] %= (mod-1);
  }
  return C;
}

vector<vector<ll>> P(vector<vector<ll>> A,ll K){
  vector<vector<ll>> R = {{1,0},{0,1}};
  while(K>0){
    if(K&1) R = mul(R,A);
    A = mul(A,A);
    K>>=1;
  }
  return R;
}

int main(){
  const int max_N = 10000000;
  vector<int> prime(max_N+1, 0);
  prime[0] = prime[1] = 1;
  for(int i=2; i <= max_N; i++){
    if(prime[i]==0){
      for(int j=i*2; j <= max_N; j+=i){
        if(prime[j]==0) prime[j]=i;
      }
      prime[i]=i;
    }
  }
  ll N,K; cin >> N >> K;
  map<int,ll> F;
  while(N>1){
    int f = prime[N];
    F[f]++;
    N/=f;
  }
  while(1){
    map<int,ll> G;
    for(auto f:F){
      int n = f.first + 1;
      map<int,ll> tmp;
      while(n>1){
        int d = prime[n];
        tmp[d]++;
        n/=d;
      }
      for(auto t:tmp){
        G[t.first] += t.second * f.second % (mod-1);
        G[t.first] %= (mod-1);
      }
    }
    K--;
    swap(F,G);
    if(K==0) break;
    if(sz(F)==2 && F.count(2) && F.count(3)) break;
    if(sz(F)==1 && (F.count(2) || F.count(3))) break;
  }

  if(K){
    vector<vector<ll>> A = {{0,2},{1,0}};
    auto AK = P(A,K);
    map<int,ll> G;
    G[2] = (AK[0][0]*F[2]+AK[0][1]*F[3])%(mod-1);
    G[3] = (AK[1][0]*F[2]+AK[1][1]*F[3])%(mod-1);
    F = G;
  }
  ll ans = 1;
  for(auto f:F){
    ans *= mpow(f.first,f.second) % mod;
    ans %= mod;
  }
  cout << ans << '\n';
  return 0;
};
0