結果
| 問題 |
No.2326 Factorial to the Power of Factorial to the...
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-03 20:50:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 105 ms / 2,000 ms |
| コード長 | 3,394 bytes |
| コンパイル時間 | 3,644 ms |
| コンパイル使用メモリ | 178,420 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-29 03:15:10 |
| 合計ジャッジ時間 | 5,682 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:87:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
87 | for(auto [j, k] : prime_factorize(p)) {
| ^
main.cpp:92:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
92 | for(auto [j, k] : prime_factorize(i)) {
| ^
main.cpp:98:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
98 | for(auto [j, l] : base) {
| ^
ソースコード
#include <algorithm>
#include <iomanip>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <numeric>
#include <vector>
#include <climits>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
//素因数分解(sqrt(n))
vector<pair<long long, long long> > prime_factorize(long long n) {
vector<pair<long long, long long> > res;
for (long long p = 2; p * p <= n; ++p) {
if (n % p != 0) continue;
int num = 0;
while (n % p == 0) { ++num; n /= p; }
res.push_back(make_pair(p, num));
}
if (n != 1) res.push_back(make_pair(n, 1));
return res;
}
template <int m>
std::istream &std::operator>>(std::istream &is, atcoder::static_modint<m> &a) {
long long v;
is >> v;
a = v;
return is;
}
template <int m>
std::istream &std::operator>>(std::istream &is, atcoder::dynamic_modint<m> &a) {
long long v;
is >> v;
a = v;
return is;
}
template <int m>
std::ostream &std::operator<<(std::ostream &os, const atcoder::static_modint<m> &a) { return os << a.val(); }
template <int m>
std::ostream &std::operator<<(std::ostream &os, const atcoder::dynamic_modint<m> &a) { return os << a.val(); }
int main() {
i64 n, p;
cin >> n >> p;
i64 m = 1e9 + 7;
modint::set_mod(m);
map<int, int> base, sum;
for(auto [j, k] : prime_factorize(p)) {
base[j] = k;
}
rep(i, 1, n + 1) {
for(auto [j, k] : prime_factorize(i)) {
sum[j] += k;
}
}
i64 k = 1e9; // N! が何回割り切れるか?
for(auto [j, l] : base) {
// cout << "val ; " << sum[j] << " , " << base[j] << endl;
chmin(k, sum[j] / base[j]);
// cout << "to : " << sum[j] / base[j] << endl;
// cout << "k: " << k << endl;
}
i64 xm = 1, xmm = 1;
rep(i, 1, n + 1) {
xm *= i;
xmm *= i;
xm %= m;
xmm %= m - 1;
}
cout << modint(k) * modint(xm).pow(xmm) << endl;
return 0;
}