結果
問題 | No.2326 Factorial to the Power of Factorial to the... |
ユーザー | keisuke6 |
提出日時 | 2023-05-28 13:41:57 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 526 bytes |
コンパイル時間 | 2,340 ms |
コンパイル使用メモリ | 199,556 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-26 21:31:52 |
合計ジャッジ時間 | 3,478 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long int int_pow(int a, int x, int mod){ if(x == 0) return 1; if(x%2 == 0){ int t = int_pow(a,x/2,mod); return t*t%mod; } else return (int_pow(a,x-1,mod)*a)%mod; } signed main(){ int N,P; cin>>N>>P; int mod = 1e9+7; int ans = 0; int a = 1, b = 1; for(int i=1;i<=N;i++){ a *= i; a %= mod; b *= i; b %= mod-1; } int t = int_pow(a,b,mod); int pp = P; while(N >= P){ ans += N/P; P *= pp; } cout<<(ans*t)%mod<<endl; }