結果
問題 | No.1411 Hundreds of Conditions Sequences |
ユーザー |
![]() |
提出日時 | 2021-02-26 23:17:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,141 bytes |
コンパイル時間 | 2,008 ms |
コンパイル使用メモリ | 173,656 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-10-02 16:15:14 |
合計ジャッジ時間 | 6,115 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 TLE * 1 |
other | -- * 62 |
ソースコード
#include <bits/stdc++.h>int ri() {int n;scanf("%d", &n);return n;}template<int mod>struct ModInt{int x;ModInt () : x(0) {}ModInt (int64_t x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {}ModInt &operator += (const ModInt &p){if ((x += p.x) >= mod) x -= mod;return *this;}ModInt &operator -= (const ModInt &p) {if ((x += mod - p.x) >= mod) x -= mod;return *this;}ModInt &operator *= (const ModInt &p) {x = (int64_t) x * p.x % mod;return *this;}ModInt &operator /= (const ModInt &p) {*this *= p.inverse();return *this;}ModInt &operator ^= (int64_t p) {ModInt res = 1;for (; p; p >>= 1) {if (p & 1) res *= *this;*this *= *this;}return *this = res;}ModInt operator - () const { return ModInt(-x); }ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }ModInt operator ^ (int64_t p) const { return ModInt(*this) ^= p; }bool operator == (const ModInt &p) const { return x == p.x; }bool operator != (const ModInt &p) const { return x != p.x; }explicit operator int() const { return x; }ModInt &operator = (const int p) { x = p; return *this;}ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;while (b > 0) {t = a / b;a -= t * b;std::swap(a, b);u -= t * v;std::swap(u, v);}return ModInt(u);}friend std::ostream & operator << (std::ostream &stream, const ModInt<mod> &p) {return stream << p.x;}friend std::istream & operator >> (std::istream &stream, ModInt<mod> &a) {int64_t x;stream >> x;a = ModInt<mod>(x);return stream;}};typedef ModInt<1000000007> mint;template<int mod> struct MComb {using mint = ModInt<mod>;std::vector<mint> fact;std::vector<mint> inv;MComb (int n) { // O(n + log(mod))fact = std::vector<mint>(n + 1, 1);for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint(i);inv.resize(n + 1);inv[n] = fact[n] ^ (mod - 2);for (int i = n; i--; ) inv[i] = inv[i + 1] * mint(i + 1);}mint ncr(int n, int r) {return fact[n] * inv[r] * inv[n - r];}mint npr(int n, int r) {return fact[n] * inv[n - r];}mint nhr(int n, int r) {assert(n + r - 1 < (int) fact.size());return ncr(n + r - 1, r);}};int gcd(int a, int b) {while (a && b) {if (a > b) a %= b;else b %= a;}return a + b;}int lcm(int a, int b) {return a / gcd(a, b) * b;}int main() {int n = ri();assert(n <= 100);// あとちょっと...int a[n];for (auto &i : a) i = ri();for (int i = 0; i < n; i++) {std::vector<int> b;for (int j = 0; j < n; j++) if (i != j) b.push_back(a[j]);auto solve = [] (std::vector<int> a) {int n = a.size();std::sort(a.begin(), a.end(), std::greater<>());mint res = 1;for (auto i : a) res *= i;int lc = 1;for (auto i : a) lc = lcm(lc, i);return res - lc;};std::cout << solve(b) << std::endl;}return 0;}