結果
問題 | No.890 移調の限られた旋法 |
ユーザー | a |
提出日時 | 2019-09-21 00:06:06 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 4,367 bytes |
コンパイル時間 | 1,670 ms |
コンパイル使用メモリ | 174,108 KB |
実行使用メモリ | 15,020 KB |
最終ジャッジ日時 | 2024-09-15 05:59:23 |
合計ジャッジ時間 | 3,041 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 19 ms
15,020 KB |
testcase_14 | AC | 19 ms
14,972 KB |
testcase_15 | AC | 19 ms
14,908 KB |
testcase_16 | AC | 20 ms
14,996 KB |
testcase_17 | AC | 18 ms
13,716 KB |
testcase_18 | AC | 18 ms
13,828 KB |
testcase_19 | AC | 13 ms
9,344 KB |
testcase_20 | AC | 9 ms
7,168 KB |
testcase_21 | AC | 3 ms
6,944 KB |
testcase_22 | AC | 16 ms
12,268 KB |
testcase_23 | AC | 18 ms
14,272 KB |
testcase_24 | AC | 12 ms
9,472 KB |
testcase_25 | AC | 5 ms
6,940 KB |
testcase_26 | AC | 19 ms
14,400 KB |
testcase_27 | AC | 19 ms
14,664 KB |
testcase_28 | AC | 14 ms
10,576 KB |
testcase_29 | AC | 10 ms
8,064 KB |
testcase_30 | AC | 18 ms
13,716 KB |
testcase_31 | AC | 12 ms
9,344 KB |
testcase_32 | AC | 18 ms
13,116 KB |
testcase_33 | AC | 18 ms
13,600 KB |
testcase_34 | AC | 18 ms
13,496 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; template <int p> struct Modint { int value; Modint() : value(0) {} Modint(long x) : value(x >= 0 ? x % p : (p + x % p) % p) {} inline Modint &operator+=(const Modint &b) { if ((this->value += b.value) >= p) this->value -= p; return (*this); } inline Modint &operator-=(const Modint &b) { if ((this->value += p - b.value) >= p) this->value -= p; return (*this); } inline Modint &operator*=(const Modint &b) { this->value = (int)((1LL * this->value * b.value) % p); return (*this); } inline Modint &operator/=(const Modint &b) { (*this) *= b.inverse(); return (*this); } Modint operator+(const Modint &b) const { return Modint(*this) += b; } Modint operator-(const Modint &b) const { return Modint(*this) -= b; } Modint operator*(const Modint &b) const { return Modint(*this) *= b; } Modint operator/(const Modint &b) const { return Modint(*this) /= b; } inline Modint &operator++(int) { return (*this) += 1; } inline Modint &operator--(int) { return (*this) -= 1; } inline bool operator==(const Modint &b) const { return this->value == b.value; } inline bool operator!=(const Modint &b) const { return this->value != b.value; } inline bool operator<(const Modint &b) const { return this->value < b.value; } inline bool operator<=(const Modint &b) const { return this->value <= b.value; } inline bool operator>(const Modint &b) const { return this->value > b.value; } inline bool operator>=(const Modint &b) const { return this->value >= b.value; } // requires that "this->value and p are co-prime" // a_i * v + a_(i+1) * p = r_i // r_i = r_(i+1) * q_(i+1) * r_(i+2) // q == 1 (i > 1) // reference: https://atcoder.jp/contests/agc026/submissions/2845729 // (line:93) inline Modint inverse() const { assert(this->value != 0); int r0 = p, r1 = this->value, a0 = 0, a1 = 1; while (r1) { int q = r0 / r1; r0 -= q * r1; swap(r0, r1); a0 -= q * a1; swap(a0, a1); } return Modint(a0); } friend istream &operator>>(istream &is, Modint<p> &a) { long t; is >> t; a = Modint<p>(t); return is; } friend ostream &operator<<(ostream &os, const Modint<p> &a) { return os << a.value; } }; const int MOD = 1e9 + 7; using Int = Modint<MOD>; Int modpow(Int e, long x) { Int res = 1; while (x > 0) { if (x & 1) res *= e; res *= res; x >>= 1; } return res; } class Comb { public: vector<Int> fact, finv; Comb(int n) : fact(n + 1), finv(n + 1) { fact[0] = Int(1); for (int i = 1; i <= n; i++) { fact[i] = fact[i - 1] * Int(i); } finv[n] = Int(fact[n]).inverse(); for (int i = n - 1; i >= 0; i--) { finv[i] = finv[i + 1] * Int(i + 1); } } inline Int nCk(int n, int k) { if (k < 0 || n < k) return Int(0); return Int(fact[n] * finv[n - k] * finv[k]); } inline Int nPk(int n, int k) { if (k < 0 || n < k) return Int(0); return Int(fact[n] * finv[n - k]); } }; vector<int> factors(int n) { vector<int> res; for (int i = 2; i * i <= n; i++) { if (n % i) continue; res.push_back(i); while (n % i == 0) { n /= i; } } if (n != 1) { res.push_back(n); } return res; } void solve() { int n, k; cin >> n >> k; Int ans = 0; vector<int> m(n + 1); Comb comb(n + 1); auto fs = factors(__gcd(n, k)); for (int s = 1; s < (1 << fs.size()); s++) { int r = 1; for (int k = 0; k < fs.size(); k++) { if (s >> k & 1) { r *= fs[k]; } } ans += Int(__builtin_popcount(s) & 1 ? 1 : -1) * comb.nCk(n / r, k / r); } cout << ans << endl; } int main() { solve(); return 0; }