結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー Etis
提出日時 2023-05-28 14:51:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 7,538 bytes
コンパイル時間 4,623 ms
コンパイル使用メモリ 259,812 KB
最終ジャッジ日時 2025-02-13 12:08:35
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11 WA * 9
権限があれば一括ダウンロードができます

ソースコード

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

//#pragma GCC target("avx")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
//local debug
#ifdef LOCAL
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif
#define overload4(a, b, c, d, e, ...) e
//alias
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using mint = modint998244353;
using Mint = modint1000000007;
//constants
constexpr const long long MOD = 998244353;
constexpr const long long MODM = 1000000007;
constexpr const int INF = 1e9;
constexpr const ll LINF = 1e18;
//rep(for-loop) macro
#define rep2(i, n) for(ll i = 0; i < n; i++)
#define rep3(i, k, n) for(ll i = k; i < n; i++)
#define rep4(i, k, n, a) for(ll i = k; i < n; i += a)
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2)(__VA_ARGS__)
#define rep1_2(i, n) for(ll i = 1; i <= n; i++)
#define rep1_3(i, k, n) for(ll i = k; i <= n; i++)
#define rep1_4(i, k, n, a) for(ll i = k; i <= n; i += a)
#define rep1(...) overload4(__VA_ARGS__, rep1_4, rep1_3, rep1_2)(__VA_ARGS__)
#define Rep2(i, n) for(ll i = n - 1; i >= 0; i--)
#define Rep3(i, k, n) for(ll i = n - 1; i >= k; i--)
#define Rep4(i, k, n, a) for(ll i = n - 1; i >= k; i -= a)
#define Rep(...) overload4(__VA_ARGS__, Rep4, Rep3, Rep2)(__VA_ARGS__)
#define Rep1_2(i, n) for(ll i = n; i >= 1; i--)
#define Rep1_3(i, k, n) for(ll i = n; i >= k; i--)
#define Rep1_4(i, k, n, a) for(ll i = n; i >= k; i -= a)
#define Rep1(...) overload4(__VA_ARGS__, Rep1_4, Rep1_3, Rep1_2)(__VA_ARGS__)
#define vfor(v, x) for(auto x : v)
#define mfor(map) for(auto &[key, value] : map)
//vector macro
#define vvecc(T, name, n, m) vector<vector<T>> name(n, vector<T>(m))
#define vvec(T, name, n) vector<vector<T>> name(n)
#define vvecs(T, name, n, m, s) vector<vector<T>> name(n, vector<T>(m, s))
#define all(x) begin(x), end(x)
#define LB(v, x) distance((v).begin(), lower_bound(all(v), (x)))
#define UB(v, x) distance((v).begin(), upper_bound(all(v), (x)))
//data structure macro
#define ef emplace_front
#define eb emplace_back
#define pf pop_front
#define pb pop_back
#define mp make_pair
#define fi first
#define se second
#define mt make_tuple
#define get(t, x) get<x - 1>(t)
#define lb lower_bound
#define ub upper_bound
template<class T> using pq = priority_queue<T>;
template<class T> using pqmin = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U> using pqp = priority_queue<pair<T, U>>;
template<class T, class U> using pqpmin = priority_queue<pair<T, U>, vector<pair<T, U>>, greater<pair<T,U>>>;
//output
#define pl() cout << '\n'
template<class T> void print(const T& a) {cout << a;}
void printl(){}
template<class T> void printl(const T& t){print(t); pl();}
template<class Head, class... Tail> void printl(const Head& head, const Tail&... tail) {print(head); cout << " "; printl(tail...);}
template<class T> void fin(const T& t) {printl(t); exit(0);}
void Yes(bool a) {cout << (a ? "Yes" : "No") << '\n';}
template<class T, class U> void Out2(bool a, T yes, U no) {if(a) printl(yes); else printl(no);}
//functions
int ctoi(char c) {return c - '0';}
char to_char(int x) {return x + '0';}
template<class... T> constexpr auto Emin(T... a) {return min(initializer_list<common_type_t<T...>>{a...});}
template<class... T> constexpr auto Emax(T... a) {return max(initializer_list<common_type_t<T...>>{a...});}
template<class T, class U> bool chmax(T &a, const U &b) {if (a < b) { a = b; return true;} return false;}
template<class T, class U> bool chmin(T &a, const U &b) {if (a > b) { a = b; return true;} return false;}
template<class T, class U> ll Epow(T x, U y) {ll ans = 1; for(int i = 0; i < y; i++) ans *= x; return ans;}
template<class T, class U> ll Eceil(T x, U y) {return (ll)ceil((ld)x / (ld)y);}
template<class T, class U> ll Efloor(T x, U y) {return (ll)floor((ld)x / (ld)y);}
template<class T, class U> bool check_bit(T tar, U bit) {return ((tar & Epow(2, bit)) != 0);}
/*Math Library<ACL>*/
//a ÷ bmod(mod) - O(log(mod))
ll div_mod(ll a, ll b, ll mod) {return (a * pow_mod(b, mod - 2, mod)) % mod;}
// - O(n)
ll factorial(ll n, ll mod) {
ll ans = 1;
for(ll i = n; i >= 2; i--) ans = (ans * i) % mod;
return ans;
}ll factorial(ll n) {return factorial(n, MOD);}
// - O(r)
ll permutation(ll n, ll r, ll mod) {
ll ans = 1;
for(ll i = 0; i < r; i++) ans = (ans * (n - i)) % mod;
return ans;
}ll permutation(ll n, ll r) {return permutation(n, r, MOD);}
//(mod) - O(min(r, n - r) + log(mod))
ll combination(ll n, ll r, ll mod) {
r = min(r, n - r);
if(r == 0) return 1;
ll up = n;
ll down = 1;
for(int i = 1; i < r; i++) {
up = (up * (n - i)) % mod;
down = (down * (i + 1)) % mod;
}
return div_mod(up, down, mod);
}ll combination(ll n, ll r) {return combination(n, r, MOD);}
//nC0~nCr(mod) - O(rlog(mod))
vector<ll> getCombination_vec(ll n, ll r, ll mod) {
vector<ll> ret(r + 1);
ret[0] = 1;
ll up = n;
ll down = 1;
ret[1] = div_mod(up, down, mod);
for(int i = 1; i < r; i++) {
up = (up * (n - i)) % mod;
down = (down * (i + 1)) % mod;
ret[i + 1] = div_mod(up, down, mod);
}
return ret;
}vector<ll> getCombination_vec(ll n, ll r) {return getCombination_vec(n, r, MOD);}
// - O(√N)
bool is_prime(ll N) {
if (N == 1) return false;
for (ll i = 2; i * i <= N; i++) {
if (N % i == 0) return false;
}
return true;
}
// - O(√N)
vector<ll> enum_divisors(ll N) {
vector<ll> res;
for (ll i = 1; i * i <= N; i++) {
if (N % i == 0) {
res.eb(i);
if (N / i != i) res.eb(N / i);
}
}
sort(all(res));
return res;
}
// - O(√N)
vector<pair<ll, ll>> prime_factorize(ll N) {
vector<pair<ll, ll>> res;
for (ll a = 2; a * a <= N; a++) {
if (N % a != 0) continue;
ll ex = 0;
while (N % a == 0) {
ex++;
N /= a;
}
res.eb(mp(a, ex));
}
if (N != 1) res.eb(mp(N, 1));
return res;
}
// - O(NloglogN)
vector<bool> Eratosthenes(ll N) {
vector<bool> isprime(N + 1, true);
isprime[0] = isprime[1] = false;
for (ll p = 2; p <= N; p++) {
if (!isprime[p]) continue;
for (ll q = p * 2; q <= N; q += p) {
isprime[q] = false;
}
}
return isprime;
}
//N - O(NloglogN)
vector<ll> getPrimes(ll N) {
vector<bool> era = Eratosthenes(N);
vector<ll> primes;
for(ll i = 2; i <= N; i++) {
if(era[i]) primes.eb(i);
}
return primes;
}
//---------------------------------------------------------------------------------------------------
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
ll N, P;
cin >> N >> P;
vector<ll> prime_cnt((N + 1) * 100, 0);
rep1(i, 2, N) {
auto ret = prime_factorize(i);
rep(j, ret.size()) prime_cnt[ret[j].fi] += ret[j].se;
}
ll div_cnt = prime_cnt[P];
ll Nfac = factorial(N, MODM);
ll r = pow_mod(Nfac, Nfac, MODM);
Mint ans = div_cnt * r;
printl(ans.val());
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0