結果

問題 No.2365 Present of good number
ユーザー srjywrdnprkt
提出日時 2023-07-09 03:19:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,807 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 213,196 KB
最終ジャッジ日時 2025-02-15 09:16:50
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll modc = 1e9+6;
class mint {
ll x;
public:
mint(ll x=0) : x((x%modc+modc)%modc) {}
mint operator-() const {
return mint(-x);
}
mint& operator+=(const mint& a) {
if ((x += a.x) >= modc) x -= modc;
return *this;
}
mint& operator-=(const mint& a) {
if ((x += modc-a.x) >= modc) x -= modc;
return *this;
}
mint& operator*=(const mint& a) {
(x *= a.x) %= modc;
return *this;
}
mint operator+(const mint& a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint& a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint& a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(modc-2);
}
mint& operator/=(const mint& a) {
return (*this) *= a.inv();
}
mint operator/(const mint& a) const {
mint res(*this);
return res/=a;
}
bool operator == (const mint& a) const{
return x == a.x;
}
friend ostream& operator<<(ostream& os, const mint& m){
os << m.x;
return os;
}
friend istream& operator>>(istream& ip, mint&m) {
ip >> m.x;
return ip;
}
ll val(){
return x;
}
};
vector<vector<mint>> dot(vector<vector<mint>> &a, vector<vector<mint>> &b){
int M = a.size();
vector<vector<mint>> c(M, vector<mint>(M));
for (int i=0; i<M; i++){
for (int k=0; k<M; k++){
for (int j=0; j<M; j++) c[i][j] += (a[i][k] * b[k][j]);
}
}
return c;
}
vector<vector<mint>> pow(vector<vector<mint>> A, ll N){
int M = A.size();
vector<vector<mint>> B(M, vector<mint>(M));
for (int i=0; i<M; i++) B[i][i] = 1;
while(N){
if (N % 2 == 1) B = dot(B, A);
N >>= 1;
A = dot(A, A);
}
return B;
}
map<ll, ll> prime_factor(ll n){
ll m = n;
map<ll, ll> prime;
if (n % 2 == 0){
while(n % 2 == 0){
prime[2]++;
n /= 2;
}
}
for (ll i = 3; i*i <= m; i+=2){
if (n % i == 0){
while(n % i == 0){
prime[i]++;
n /= i;
}
}
}
if (n != 1){
prime[n]++;
}
return prime;
}
ll mod_exp(ll b, ll e, ll m){
if (e > 0 && b == 0) return 0;
ll ans = 1;
b %= m;
while (e > 0){
if ((e & 1LL)) ans = (ans * b) % m;
e = e >> 1LL;
b = (b*b) % m;
}
return ans;
}
const ll modc2 = 1e9+7;
int main(){
ll N, K;
cin >> N >> K;
map<ll, ll> mp = prime_factor(N), pr;
for (int i=0; i<min(K, 60LL); i++){
map<ll, ll> mp2;
for (auto [p, e] : mp){
pr = prime_factor(p+1);
for (auto [p1, e1] : pr){
mp2[p1] += (e1 * e) % modc;
mp2[p1] %= modc;
}
}
swap(mp, mp2);
}
if (K <= 60){
ll ans=1;
for (auto [p, e] : mp){
ans *= mod_exp(p, e, modc2);
ans %= modc2;
}
cout << ans << endl;
return 0;
}
K -= 60;
for (auto [x, y] : mp) assert(x == 2 || x == 3);
vector<vector<mint>> m = {{0, 2}, {1, 0}};
m = pow(m, K);
mint two, thr;
ll ans=1;
two = m[0][0] * mp[2] + m[0][1] * mp[3];
thr = m[1][0] * mp[2] + m[1][1] * mp[3];
ans *= mod_exp(2, two.val(), modc2);
ans %= modc2;
ans *= mod_exp(3, thr.val(), modc2);
ans %= modc2;
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0