結果
問題 | No.2365 Present of good number |
ユーザー |
![]() |
提出日時 | 2023-06-30 22:31:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,614 bytes |
コンパイル時間 | 1,913 ms |
コンパイル使用メモリ | 179,364 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-07 10:23:05 |
合計ジャッジ時間 | 2,950 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 39 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;using P = pair<ll,ll>;#define fix(x) fixed << setprecision(x)#define asc(x) x, vector<x>, greater<x>#define rep(i, n) for(ll i = 0; i < n; i++)#define all(x) (x).begin(),(x).end()template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}constexpr ll INFLL = (1LL << 62), MOD = 1e9+7;constexpr int INF = (1 << 30);ll mpow(ll x, ll y, ll MOD_ = MOD){ll res = 1; x %= MOD_;while(y){if(y%2) res = res * x % MOD_;x = x * x % MOD_;y /= 2;}return res;}struct PrimeNumber{vector<int> _PN;vector<bool> _B;int n;PrimeNumber(int _n=0){init(_n);}void init(int _n){n = _n;_B.assign(n+1,true);_B[1] = false;for(int i=2;i<=n;i++){if(_B[i]){_PN.push_back(i);for(int j=2*i;j<=n;j+=i) _B[j] = false;}}}bool isprime_big(ll x){ll m = n;assert(x<=m*m);for(int &y:_PN){if(y*y>x) break;if(!(x%y)) return false;}return true;}bool isprime(ll x){assert(0<x);if(n<x) return isprime_big(x);return _B[x];}vector<int> pnlist(){ return _PN; };};int main(){cin.tie(nullptr);ios::sync_with_stdio(false);PrimeNumber P(320);auto pn = P.pnlist();ll n,k;cin >> n >> k;ll t2 = 0, t3 = 0;vector<int> p;for(int d:pn){if(n==1) break;while(!(n%d)){if(d==2) t2++;else if(d==3) t3++;else p.push_back(d);n /= d;}}if(n>1) p.push_back(n);while(k){if(!p.size()) break;k--;t3 = t3 * 2 % (MOD-1);swap(t2,t3);vector<int> upd;for(int x:p){x++;for(int d:pn){if(x==1) break;while(!(x%d)){if(d==2) t2++;else if(d==3) t3++;else upd.push_back(d);x /= d;}}if(x>1) upd.push_back(x);}p = upd;}t2 = t2 * mpow(2,k/2,MOD-1) % (MOD-1);t3 = t3 * mpow(2,k/2,MOD-1) % (MOD-1);if(k&1){t3 = t3 * 2 % (MOD-1);swap(t2,t3);}ll ans = mpow(2,t2)*mpow(3,t3)%MOD;for(int x:p) ans = ans * (x) % MOD;cout << ans << '\n';return 0;}