結果
問題 | No.2326 Factorial to the Power of Factorial to the... |
ユーザー | seiyu |
提出日時 | 2023-06-03 20:50:34 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 102 ms / 2,000 ms |
コード長 | 3,394 bytes |
コンパイル時間 | 3,367 ms |
コンパイル使用メモリ | 177,340 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-09 03:44:21 |
合計ジャッジ時間 | 5,303 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
5,248 KB |
testcase_01 | AC | 102 ms
5,376 KB |
testcase_02 | AC | 21 ms
5,376 KB |
testcase_03 | AC | 73 ms
5,376 KB |
testcase_04 | AC | 45 ms
5,376 KB |
testcase_05 | AC | 35 ms
5,376 KB |
testcase_06 | AC | 63 ms
5,376 KB |
testcase_07 | AC | 96 ms
5,376 KB |
testcase_08 | AC | 98 ms
5,376 KB |
testcase_09 | AC | 99 ms
5,376 KB |
testcase_10 | AC | 7 ms
5,376 KB |
testcase_11 | AC | 15 ms
5,376 KB |
testcase_12 | AC | 5 ms
5,376 KB |
testcase_13 | AC | 41 ms
5,376 KB |
testcase_14 | AC | 82 ms
5,376 KB |
testcase_15 | AC | 10 ms
5,376 KB |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | AC | 85 ms
5,376 KB |
testcase_18 | AC | 26 ms
5,376 KB |
testcase_19 | AC | 8 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
コンパイルメッセージ
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; }