結果
問題 | No.2365 Present of good number |
ユーザー | rnano |
提出日時 | 2023-07-01 00:25:33 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 21 ms / 2,000 ms |
コード長 | 4,420 bytes |
コンパイル時間 | 1,805 ms |
コンパイル使用メモリ | 186,840 KB |
実行使用メモリ | 9,952 KB |
最終ジャッジ日時 | 2024-07-07 11:46:45 |
合計ジャッジ時間 | 3,408 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
9,488 KB |
testcase_01 | AC | 18 ms
9,100 KB |
testcase_02 | AC | 18 ms
9,548 KB |
testcase_03 | AC | 18 ms
9,440 KB |
testcase_04 | AC | 18 ms
9,196 KB |
testcase_05 | AC | 18 ms
9,264 KB |
testcase_06 | AC | 18 ms
8,080 KB |
testcase_07 | AC | 17 ms
9,396 KB |
testcase_08 | AC | 17 ms
9,056 KB |
testcase_09 | AC | 18 ms
9,952 KB |
testcase_10 | AC | 18 ms
9,692 KB |
testcase_11 | AC | 18 ms
9,288 KB |
testcase_12 | AC | 18 ms
9,764 KB |
testcase_13 | AC | 18 ms
9,264 KB |
testcase_14 | AC | 18 ms
9,244 KB |
testcase_15 | AC | 18 ms
9,068 KB |
testcase_16 | AC | 18 ms
9,112 KB |
testcase_17 | AC | 17 ms
9,436 KB |
testcase_18 | AC | 17 ms
8,072 KB |
testcase_19 | AC | 18 ms
9,032 KB |
testcase_20 | AC | 17 ms
9,412 KB |
testcase_21 | AC | 18 ms
9,224 KB |
testcase_22 | AC | 18 ms
9,556 KB |
testcase_23 | AC | 19 ms
9,568 KB |
testcase_24 | AC | 20 ms
9,860 KB |
testcase_25 | AC | 18 ms
8,084 KB |
testcase_26 | AC | 19 ms
8,192 KB |
testcase_27 | AC | 19 ms
9,556 KB |
testcase_28 | AC | 21 ms
9,516 KB |
testcase_29 | AC | 18 ms
9,112 KB |
testcase_30 | AC | 18 ms
9,004 KB |
testcase_31 | AC | 17 ms
9,032 KB |
testcase_32 | AC | 18 ms
9,768 KB |
testcase_33 | AC | 18 ms
9,728 KB |
testcase_34 | AC | 17 ms
9,380 KB |
testcase_35 | AC | 18 ms
9,920 KB |
testcase_36 | AC | 17 ms
8,924 KB |
testcase_37 | AC | 18 ms
9,360 KB |
testcase_38 | AC | 18 ms
9,240 KB |
testcase_39 | AC | 18 ms
9,192 KB |
testcase_40 | AC | 18 ms
9,124 KB |
ソースコード
#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; */ }