結果
問題 | No.2365 Present of good number |
ユーザー |
|
提出日時 | 2023-06-30 22:18:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 197 ms / 2,000 ms |
コード長 | 2,557 bytes |
コンパイル時間 | 1,795 ms |
コンパイル使用メモリ | 145,424 KB |
最終ジャッジ日時 | 2025-02-15 04:06:11 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 39 |
ソースコード
#include <iostream>#include <string>#include <vector>#include <algorithm>#include <functional>#include <cmath>#include <iomanip>#include <stack>#include <queue>#include <numeric>#include <map>#include <unordered_map>#include <set>#include <fstream>#include <chrono>#include <random>#include <bitset>//#include <atcoder/all>#define rep(i,n) for(int i=0;i<(n);i++)#define all(x) x.begin(), x.end()#define rall(x) x.rbegin(), x.rend()#define sz(x) ((int)(x).size())#define pb push_backusing ll = long long;using namespace std;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; }ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}const ll mod = 1000000007;ll mpow(ll a, ll x){ll res = 1;while(x > 0){if(x & 1) res = (res * a) % mod;a = (a * a) % mod;x >>= 1;}return res;}vector<vector<ll>> mul(vector<vector<ll>> A, vector<vector<ll>> B){vector<vector<ll>> C(2,vector<ll>(2,0));rep(i,2) rep(j,2) rep(k,2){C[i][j] += A[i][k] * B[k][j] % (mod-1);C[i][j] %= (mod-1);}return C;}vector<vector<ll>> P(vector<vector<ll>> A,ll K){vector<vector<ll>> R = {{1,0},{0,1}};while(K>0){if(K&1) R = mul(R,A);A = mul(A,A);K>>=1;}return R;}int main(){const int max_N = 10000000;vector<int> prime(max_N+1, 0);prime[0] = prime[1] = 1;for(int i=2; i <= max_N; i++){if(prime[i]==0){for(int j=i*2; j <= max_N; j+=i){if(prime[j]==0) prime[j]=i;}prime[i]=i;}}ll N,K; cin >> N >> K;map<int,ll> F;while(N>1){int f = prime[N];F[f]++;N/=f;}while(1){map<int,ll> G;for(auto f:F){int n = f.first + 1;map<int,ll> tmp;while(n>1){int d = prime[n];tmp[d]++;n/=d;}for(auto t:tmp){G[t.first] += t.second * f.second % (mod-1);G[t.first] %= (mod-1);}}K--;swap(F,G);if(K==0) break;if(sz(F)==2 && F.count(2) && F.count(3)) break;if(sz(F)==1 && (F.count(2) || F.count(3))) break;}if(K){vector<vector<ll>> A = {{0,2},{1,0}};auto AK = P(A,K);map<int,ll> G;G[2] = (AK[0][0]*F[2]+AK[0][1]*F[3])%(mod-1);G[3] = (AK[1][0]*F[2]+AK[1][1]*F[3])%(mod-1);F = G;}ll ans = 1;for(auto f:F){ans *= mpow(f.first,f.second) % mod;ans %= mod;}cout << ans << '\n';return 0;};