結果

問題 No.2365 Present of good number
ユーザー untiunti
提出日時 2023-07-04 04:42:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 4,216 bytes
コンパイル時間 3,380 ms
コンパイル使用メモリ 224,612 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 02:09:57
合計ジャッジ時間 5,251 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>; 
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


//  ダイクストラ ひーぷ 
/* dijkstra(G,s,dis)
    入力:グラフ G, 開始点 s, 距離を格納する dis
    計算量:O(|E|log|V|)
    副作用:dis が書き換えられる
*/
// グラフ スタート 距離 ひとつ前
void dijkstra(const graph & g, ll s ,vector<ll> & d,vector<ll> &prev ){
   ll N = g.size() ; //頂点数
   d.resize(N,INF) ;
   prev.resize(N,INF) ;
   priority_queue<P,vector<P>,greater<P>> pq ;
   d[s]=0 ;
   pq.emplace(d[s],s) ;
   while(!pq.empty()){
       P p=pq.top() ;
       pq.pop() ;
       ll v= p.se;
       if(d[v]<p.fi) continue ;
       for(auto & e :g[v]){
           if(d[e.to]>d[v]+e.cost){
               d[e.to]=d[v]+e.cost ;
               prev[e.to]=v ;  //頂点vを使ってe.toに辿り着いた
               pq.emplace(d[e.to],e.to) ;
           }
       }
    } 
}

/* get_path(prev, t)
    入力:dijkstra で得た prev, ゴール t
    出力: t への最短路のパス
*/
vector<ll> get_path(const vector<ll> &prev, ll t) {
    vector<ll> path;
    for (ll cur = t; cur != -1; cur = prev[cur]) {
        path.push_back(cur);
    }
    reverse(path.begin(), path.end()); // 逆順なのでひっくり返す
    return path;
}

map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
  if(n!=1) ord[n]++;
  return ord ;
 }

vector< int > z_algorithm(const string &s) {
  vector< int > prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}

const ll mod=1e9+7;

ll modpow(ll x, ll y){
  if(y==0) return 1;
  else{
    ll ans=modpow(x,y/2);
    ans=(ans*ans)%mod;
    if(y%2) return (ans*x)%mod;
    else return ans;
  }
}

const ll mmod=1e9+6;

ll mmodpow(ll x, ll y){
  if(y==0) return 1;
  else{
    ll ans=mmodpow(x,y/2);
    ans=(ans*ans)%mmod;
    if(y%2) return (ans*x)%mmod;
    else return ans;
  }
}

int main(){
  
  ll n,k; cin>>n>>k;
  
  map<ll,ll> mp;
  ll nn=n;
  for(ll i=2;i*i<=nn;++i){
    while(n%i==0){
      n/=i; mp[i]++;
    }
  }

  if(n!=1) mp[n]++;

  ll MA=0ll;
  for(auto u:mp) chmax(MA,u.fi);


  while(k>0&&MA>3){
    k--;  
    map<ll,ll> pm;
    for(auto u:mp){  
      ll num=u.fi+1;
      ll p=u.se;
      map<ll,ll> f=factor(num);
      for(auto v:f) pm[v.fi]+=v.se*p;
    }
    mp=pm;
    MA=0ll;
    for(auto u:mp) chmax(MA,u.fi);
  }


  if(!k){
    ll ans=1;
    for(auto u:mp){
      ll p=modpow(u.fi,u.se);
      ans*=p;
      ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
  }

  ll a=mp[2]; ll b=mp[3];
  
  ll ans=a;
  ll bns=b;
  ans*=mmodpow(2ll,k/2);
  bns*=mmodpow(2ll,k/2);
  ans%=mmod; bns%=mmod;
  
  if(k%2){
    bns*=2; bns%=mmod;
    swap(ans,bns);
  }

  ll p=modpow(2,ans);
  ll q=modpow(3,bns);

  //cout<<p<<" "<<q<<endl;

  p*=q; p%=mod;
  cout<<p<<endl;

  
}
0