結果

問題 No.2365 Present of good number
ユーザー rnanornano
提出日時 2023-06-30 23:44:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,262 bytes
コンパイル時間 3,571 ms
コンパイル使用メモリ 184,476 KB
実行使用メモリ 10,304 KB
最終ジャッジ日時 2023-09-21 17:55:36
合計ジャッジ時間 4,980 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
    }
    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, 52) {
    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);
  */
}
0