結果

問題 No.2365 Present of good number
ユーザー rnanornano
提出日時 2023-07-01 00:25:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 4,420 bytes
コンパイル時間 1,897 ms
コンパイル使用メモリ 185,052 KB
実行使用メモリ 8,144 KB
最終ジャッジ日時 2023-09-21 18:11:09
合計ジャッジ時間 4,364 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
7,952 KB
testcase_01 AC 23 ms
7,904 KB
testcase_02 AC 22 ms
8,068 KB
testcase_03 AC 22 ms
7,924 KB
testcase_04 AC 22 ms
8,036 KB
testcase_05 AC 22 ms
7,920 KB
testcase_06 AC 22 ms
8,008 KB
testcase_07 AC 22 ms
7,904 KB
testcase_08 AC 22 ms
7,924 KB
testcase_09 AC 22 ms
7,900 KB
testcase_10 AC 22 ms
7,888 KB
testcase_11 AC 22 ms
7,948 KB
testcase_12 AC 22 ms
8,136 KB
testcase_13 AC 22 ms
7,904 KB
testcase_14 AC 22 ms
8,016 KB
testcase_15 AC 22 ms
7,992 KB
testcase_16 AC 22 ms
7,912 KB
testcase_17 AC 22 ms
7,952 KB
testcase_18 AC 22 ms
8,068 KB
testcase_19 AC 22 ms
7,952 KB
testcase_20 AC 22 ms
7,900 KB
testcase_21 AC 22 ms
7,952 KB
testcase_22 AC 22 ms
7,888 KB
testcase_23 AC 22 ms
7,972 KB
testcase_24 AC 22 ms
7,872 KB
testcase_25 AC 22 ms
7,868 KB
testcase_26 AC 22 ms
7,900 KB
testcase_27 AC 22 ms
8,144 KB
testcase_28 AC 22 ms
7,916 KB
testcase_29 AC 23 ms
7,908 KB
testcase_30 AC 22 ms
8,012 KB
testcase_31 AC 22 ms
7,892 KB
testcase_32 AC 22 ms
7,932 KB
testcase_33 AC 22 ms
7,952 KB
testcase_34 AC 22 ms
8,012 KB
testcase_35 AC 22 ms
7,956 KB
testcase_36 AC 22 ms
7,896 KB
testcase_37 AC 22 ms
7,932 KB
testcase_38 AC 22 ms
7,880 KB
testcase_39 AC 22 ms
7,976 KB
testcase_40 AC 22 ms
8,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n-1); i >= 0; --i)
#define Rep(i,a,b) for (int i = a; i < b; ++i)
#define rRep(i,a,b) for (int i = a; i > b; --i)
#define fore(i,a) for(auto &i:a)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define Unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define Bit(x,i) (((x)>>(i))&1)
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
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; }
struct settings{settings(){ios_base::sync_with_stdio(0); cin.tie(0); cout<<fixed<<setprecision(15);};}settingss;
const double PI = acos(-1);
const int INF = 1001001001;
const ll LINF = 1001001001001001001LL;

const int mod = 1000000007;
class modint {
  long long x;
public:
  modint(long long x=0) : x((x%mod+mod)%mod) {}
  modint operator-() const {
    return modint(-x);
  }
  modint& operator+=(const modint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  modint& operator-=(const modint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  modint& operator*=(const  modint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  modint operator+(const modint& a) const {
    modint res(*this);
    return res+=a;
  }
  modint operator-(const modint& a) const {
    modint res(*this);
    return res-=a;
  }
  modint operator*(const modint& a) const {
    modint res(*this);
    return res*=a;
  }
  modint pow(ll t) const {
    if (!t) return 1;
    modint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  modint inv() const {
    return pow(mod-2);
  }
  modint& operator/=(const modint& a) {
    return (*this) *= a.inv();
  }
  modint operator/(const modint& a) const {
    modint res(*this);
    return res/=a;
  }
  friend ostream& operator<<(ostream& os, const modint& m){
    os << m.x;
    return os;
  }
};

ll powmod(ll n, ll p, ll m) {
  if(p == 0) return 1;
  ll res = powmod(n, p/2, m);
  n %= m;
  if(p%2 == 0) return (res*res) % m;
  return (((res*res) % m)*n) % m;
}

vector<int> Eratosthenes(int N) {
  vector<bool> is_prime(N+1);
  for(int i=0; i<=N; ++i) {
    is_prime[i] = true;
  }
  vector<int> ret;
  for(int i=2; i<=N; ++i) {
    if(is_prime[i]) {
      for(int j=2*i; j<=N; j+=i) {
        is_prime[j] = false;
      }
      ret.emplace_back(i);
    }
  }
  return ret;
}

ll dp[100][10010];
map<ll, ll> mp;
vector<vector<pll>> nx(10010);

int main() {
  ll N, K; cin >> N >> K;
  vi prm = Eratosthenes(100000);
  int ps = prm.size();
  ll iid = 0;
  fore(p, prm) {
    mp[p] = iid;
    ++iid;
  }
  int NN = N;
  for(int i = 2; i*i <= NN; ++i) {
    int cnt = 0;
    while(N % i == 0) {
      cnt++;
      N /= i;
    }
    if(cnt > 0) dp[0][mp[i]] = cnt;
  }
  if(N > 1) dp[0][mp[N]] = 1;
  rep(i, ps) {
    int pp = prm[i]+1;
    int ppp = pp;
    for(int j = 2; j * j <= ppp; ++j) {
      int cnt = 0;
      while(pp % j == 0) {
        pp /= j;
        cnt++;
      }
      if(cnt > 0) {
        nx[i].push_back({mp[j], cnt});
      }
    }
    if(pp > 1) {
      nx[i].push_back({mp[pp], 1LL});
    }
  }
  rep(k, 51) {
    rep(i, ps) {
      fore(nnx, nx[i]) {
        dp[k+1][nnx.first] += nnx.second * dp[k][i];
      }
    }
  }
  modint ans = 1;
  if(K < 50) {
    rep(i, ps) {
      ans *= powmod(prm[i], dp[K][i], mod);
    }
    cout << ans << endl;
    return 0;
  }
  K -= 50;
  ll two = dp[50][0];
  ll thr = dp[50][1];
  ll mm = K%2;
  K /= 2;
  // 2^(two * 2^K)
  ll ppow = powmod(2, K, mod-1);
  // cout << two << ' ' << thr << ' ' << ppow << endl;
  if(mm) {
    ans *= powmod(3, two * ppow, mod);
    ans *= powmod(2, thr * ppow * 2, mod);
  } else {
    ans *= powmod(2, two * ppow, mod);
    ans *= powmod(3, thr * ppow, mod);
  }
  cout << ans << endl;
  /*
  ll KK = 1000000000000LL;
  ll pppow = powmod(2, KK/2, mod-1);
  // 2^2^KK
  cout << pppow << endl;
  cout << powmod(2, pppow, mod);
  modint aa = 1;
  aa *= powmod(3, powmod(2, 11/2, mod-1), mod);
  aa *= powmod(2, 2 * powmod(2, 11/2, mod-1) * 2, mod);
  cout << aa << endl;
  */
}
0