結果
問題 | No.890 移調の限られた旋法 |
ユーザー | hashiryo |
提出日時 | 2020-06-15 21:26:09 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 3,415 bytes |
コンパイル時間 | 1,495 ms |
コンパイル使用メモリ | 171,400 KB |
実行使用メモリ | 18,816 KB |
最終ジャッジ日時 | 2024-07-03 11:33:34 |
合計ジャッジ時間 | 2,848 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 31 ms
18,816 KB |
testcase_14 | AC | 26 ms
18,816 KB |
testcase_15 | AC | 26 ms
18,688 KB |
testcase_16 | AC | 29 ms
18,812 KB |
testcase_17 | AC | 25 ms
17,280 KB |
testcase_18 | AC | 26 ms
17,152 KB |
testcase_19 | AC | 17 ms
11,392 KB |
testcase_20 | AC | 11 ms
8,320 KB |
testcase_21 | AC | 4 ms
5,376 KB |
testcase_22 | AC | 22 ms
15,136 KB |
testcase_23 | AC | 26 ms
18,028 KB |
testcase_24 | AC | 17 ms
11,648 KB |
testcase_25 | AC | 5 ms
5,376 KB |
testcase_26 | AC | 27 ms
18,176 KB |
testcase_27 | AC | 26 ms
18,432 KB |
testcase_28 | AC | 18 ms
13,056 KB |
testcase_29 | AC | 12 ms
9,600 KB |
testcase_30 | AC | 25 ms
17,272 KB |
testcase_31 | AC | 17 ms
11,264 KB |
testcase_32 | AC | 25 ms
16,240 KB |
testcase_33 | AC | 30 ms
16,896 KB |
testcase_34 | AC | 26 ms
17,024 KB |
ソースコード
#include <bits/stdc++.h> #define debug(x) cerr << #x << ": " << x << endl #define debugArray(x, n) \ for (long long hoge = 0; (hoge) < (n); ++(hoge)) \ cerr << #x << "[" << hoge << "]: " << x[hoge] << endl using namespace std; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % 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 = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { return *this *= p.inverse(); } ModInt operator-() const { return ModInt() - *this; } 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; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b) t = a / b, swap(a -= t * b, b), swap(u -= t * v, v); return ModInt(u); } ModInt pow(int64_t e) const { ModInt ret(1); for (ModInt b = *this; e; e >>= 1, b *= b) if (e & 1) ret *= b; return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int modulo() { return mod; } }; template <class Modint> struct Combination { static vector<Modint> _fact, _finv, _inv; static void init(int sz) { int n = min(sz, Modint::modulo() - 1); _fact.resize(n + 1), _finv.resize(n + 1), _inv.resize(n + 1); for (int i = 0; i <= n; ++i) _fact[i] = i ? Modint(i) * _fact[i - 1] : 1; _finv[n] = _fact[n].inverse(); for (int i = n; i; --i) _finv[i - 1] = Modint(i) * _finv[i]; for (int i = 1; i <= n; ++i) _inv[i] = _finv[i] * _fact[i - 1]; } static Modint inverse(int n) { return _inv[n]; } static Modint fact(int n, bool inv = 0) { return inv ? _finv[n] : _fact[n]; } static Modint nPr(int n, int r) { if (n < r || r < 0) return Modint(0); return _fact[n] * _finv[n - r]; } static Modint nCr(int n, int r) { return nPr(n, r) * _finv[r]; } static Modint nHr(int n, int r) { return !r ? Modint(1) : nCr(n + r - 1, r); } static size_t size() { return _inv.size(); } }; template <class Modint> vector<Modint> Combination<Modint>::_fact; template <class Modint> vector<Modint> Combination<Modint>::_finv; template <class Modint> vector<Modint> Combination<Modint>::_inv; signed main() { cin.tie(0); ios::sync_with_stdio(false); using Mint = ModInt<int(1e9 + 7)>; using Comb = Combination<Mint>; int N, K; cin >> N >> K; Comb::init(N); Mint dp[N]; fill(dp, dp + N, 0); Mint ans = 0; for (int i = 1; i < N; i++) if (N % i == 0) { int P = N / i; if (K % P == 0) { dp[i] += Comb::nCr(i, K / P); ans += dp[i]; for (int j = 2 * i; j < N; j += i) dp[j] -= dp[i]; } } cout << ans << endl; return 0; }