結果
問題 | No.1411 Hundreds of Conditions Sequences |
ユーザー | cn_449 |
提出日時 | 2021-04-20 09:28:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 225 ms / 2,000 ms |
コード長 | 5,720 bytes |
コンパイル時間 | 1,649 ms |
コンパイル使用メモリ | 150,144 KB |
実行使用メモリ | 72,796 KB |
最終ジャッジ日時 | 2024-07-04 05:15:42 |
合計ジャッジ時間 | 18,497 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 101 ms
61,820 KB |
testcase_01 | AC | 101 ms
61,840 KB |
testcase_02 | AC | 100 ms
61,844 KB |
testcase_03 | AC | 101 ms
61,868 KB |
testcase_04 | AC | 100 ms
61,756 KB |
testcase_05 | AC | 99 ms
61,820 KB |
testcase_06 | AC | 98 ms
61,964 KB |
testcase_07 | AC | 101 ms
61,832 KB |
testcase_08 | AC | 98 ms
61,804 KB |
testcase_09 | AC | 99 ms
61,884 KB |
testcase_10 | AC | 102 ms
61,788 KB |
testcase_11 | AC | 101 ms
61,664 KB |
testcase_12 | AC | 194 ms
71,064 KB |
testcase_13 | AC | 173 ms
68,664 KB |
testcase_14 | AC | 146 ms
65,324 KB |
testcase_15 | AC | 169 ms
68,384 KB |
testcase_16 | AC | 109 ms
62,284 KB |
testcase_17 | AC | 170 ms
68,304 KB |
testcase_18 | AC | 195 ms
70,952 KB |
testcase_19 | AC | 198 ms
71,888 KB |
testcase_20 | AC | 138 ms
65,364 KB |
testcase_21 | AC | 206 ms
72,520 KB |
testcase_22 | AC | 140 ms
65,672 KB |
testcase_23 | AC | 198 ms
71,136 KB |
testcase_24 | AC | 100 ms
61,868 KB |
testcase_25 | AC | 195 ms
70,960 KB |
testcase_26 | AC | 154 ms
68,364 KB |
testcase_27 | AC | 138 ms
65,336 KB |
testcase_28 | AC | 176 ms
69,432 KB |
testcase_29 | AC | 112 ms
62,676 KB |
testcase_30 | AC | 160 ms
67,432 KB |
testcase_31 | AC | 154 ms
66,948 KB |
testcase_32 | AC | 200 ms
72,536 KB |
testcase_33 | AC | 204 ms
72,588 KB |
testcase_34 | AC | 210 ms
72,616 KB |
testcase_35 | AC | 212 ms
72,456 KB |
testcase_36 | AC | 212 ms
72,640 KB |
testcase_37 | AC | 212 ms
72,556 KB |
testcase_38 | AC | 211 ms
72,460 KB |
testcase_39 | AC | 214 ms
72,620 KB |
testcase_40 | AC | 213 ms
72,636 KB |
testcase_41 | AC | 210 ms
72,572 KB |
testcase_42 | AC | 208 ms
72,472 KB |
testcase_43 | AC | 216 ms
72,624 KB |
testcase_44 | AC | 211 ms
72,584 KB |
testcase_45 | AC | 210 ms
72,492 KB |
testcase_46 | AC | 212 ms
72,456 KB |
testcase_47 | AC | 210 ms
72,468 KB |
testcase_48 | AC | 214 ms
72,624 KB |
testcase_49 | AC | 211 ms
72,564 KB |
testcase_50 | AC | 216 ms
72,572 KB |
testcase_51 | AC | 215 ms
72,644 KB |
testcase_52 | AC | 215 ms
72,788 KB |
testcase_53 | AC | 218 ms
72,784 KB |
testcase_54 | AC | 217 ms
72,744 KB |
testcase_55 | AC | 214 ms
72,744 KB |
testcase_56 | AC | 225 ms
72,796 KB |
testcase_57 | AC | 216 ms
72,640 KB |
testcase_58 | AC | 211 ms
72,636 KB |
testcase_59 | AC | 213 ms
72,768 KB |
testcase_60 | AC | 214 ms
72,780 KB |
testcase_61 | AC | 211 ms
72,732 KB |
testcase_62 | AC | 161 ms
68,124 KB |
testcase_63 | AC | 191 ms
68,072 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_set> #include <unordered_map> #define all(a) (a).begin(), (a).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define range(i, a, b) for (ll i = (a); i < (b); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; template<class T> using pri_s = priority_queue<T, vector<T>, greater<T>>; template<class T> using pri_b = priority_queue<T>; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr int mod1e9 = 1000000007; constexpr int mod998 = 998244353; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; }; int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 }; ll mul(ll a, ll b) { return (a > INF / b ? INF : a * b); } void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); } template<class T> void er(T a) { cout << a << '\n'; exit(0); } template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; } template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; } template<class T, class U> ostream &operator << (ostream &s, const pair<T, U> &p) { s << p.first << ' ' << p.second; return s; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } }fastio_; constexpr ll mod = mod1e9; template <int mod> class modint { public: int n; modint() : n(0) {}; modint(ll n_) { n = n_ % mod; if (n < 0) n += mod; } modint operator -() const { return n > 0 ? mod - n : -n; } bool operator == (const modint &m) const { return n == m.n; } bool operator != (const modint &m) const { return n != m.n; } modint &operator += (const modint &m) { n += m.n; if (n >= mod) n -= mod; return *this; } modint &operator -= (const modint &m) { n -= m.n; if (n < 0) n += mod; return *this; } modint &operator *= (const modint &m) { n = ll(n) * m.n % mod; return *this; } modint &operator /= (const modint &m) { n = ll(n) * modinv(m).n % mod; return *this; } modint operator +(modint m) const { return modint(*this) += m; } modint operator -(modint m) const { return modint(*this) -= m; } modint operator *(modint m) const { return modint(*this) *= m; } modint operator /(modint m) const { return modint(*this) /= m; } modint &operator ++ () { *this += 1; return *this; } modint operator ++ (int) { *this += 1; return *this - 1; } modint &operator -- () { *this -= 1; return *this; } modint operator -- (int) { *this -= 1; return *this + 1; } modint pow(ll b) const { modint res = 1, a = modint(*this); while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } friend istream &operator >> (istream &s, modint<mod> &a) { s >> a.n; return s; } friend ostream &operator << (ostream &s, modint<mod> &a) { s << a.n; return s; } }; using mint = modint<mod>; vector<mint> fac, inv, facinv; mint modinv(mint x) { ll a = x.n; if (a == 0) abort(); if (a < (ll)inv.size()) return inv[a]; ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } mint res = u; return res; } void modcalc(int n) { fac.resize(n); inv.resize(n); facinv.resize(n); fac[0] = 1; fac[1] = 1; inv[1] = 1; facinv[0] = 1; facinv[1] = 1; for (ll i = 2; i < n; i++) { fac[i] = fac[i - 1] * i; inv[i] = -inv[mod % i] * (mod / i); facinv[i] = facinv[i - 1] * inv[i]; } } mint comb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * facinv[k] * facinv[n - k]; } mint perm(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * facinv[n - k]; } mint hom(ll n, ll k) { if (n < 0 || k < 0 || n == 0 && k > 0) return 0; if (n == 0 && k == 0) return 1; return fac[n + k - 1] * facinv[k] * facinv[n - 1]; } int main() { int n; cin >> n; vector<int> a(n); cin >> a; const int N = ten(6) + 10; vector<int> mf(N, -1); for (int i = 2; i < N; i++) { if (mf[i] == -1) { for (int j = i; j < N; j += i) { if (mf[j] == -1) mf[j] = i; } } } vector<vector<P>> v(n, vector<P>()); rep(i, n) { int x = a[i]; while (x > 1) { if (v[i].empty() || v[i].back().first != mf[x]) v[i].pb({ mf[x],1 }); else v[i].back().second++; x /= mf[x]; } } vector<vector<int>> f(N, vector<int>()); rep(i, n) { for (P p : v[i]) { f[p.first].pb(p.second); } } rep(i, N) f[i].pb(0); rep(i, N) sort(all(f[i]), greater<>()); mint prod = 1; rep(i, n) prod *= a[i]; mint ng = 1; rep(i, N) ng *= mint(i).pow(f[i][0]); rep(i, n) { mint ans = prod / a[i]; mint m = ng; for (P p : v[i]) { if (f[p.first][0] == p.second) { m /= mint(p.first).pow(f[p.first][0]); m *= mint(p.first).pow(f[p.first][1]); } } ans -= m; cout << ans << '\n'; } }