結果

問題 No.890 移調の限られた旋法
ユーザー pekempeypekempey
提出日時 2019-09-20 22:07:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 2,518 bytes
コンパイル時間 1,792 ms
コンパイル使用メモリ 171,740 KB
実行使用メモリ 13,232 KB
最終ジャッジ日時 2023-10-12 19:22:12
合計ジャッジ時間 4,188 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 62 ms
13,144 KB
testcase_14 AC 44 ms
6,984 KB
testcase_15 AC 62 ms
13,212 KB
testcase_16 AC 62 ms
13,232 KB
testcase_17 AC 56 ms
12,152 KB
testcase_18 AC 56 ms
12,208 KB
testcase_19 AC 34 ms
9,376 KB
testcase_20 AC 15 ms
4,440 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 48 ms
11,012 KB
testcase_23 AC 42 ms
6,664 KB
testcase_24 AC 36 ms
9,560 KB
testcase_25 AC 7 ms
4,348 KB
testcase_26 AC 59 ms
12,860 KB
testcase_27 AC 50 ms
9,556 KB
testcase_28 AC 28 ms
5,348 KB
testcase_29 AC 26 ms
7,388 KB
testcase_30 AC 56 ms
12,192 KB
testcase_31 AC 29 ms
7,556 KB
testcase_32 AC 52 ms
11,472 KB
testcase_33 AC 55 ms
11,816 KB
testcase_34 AC 52 ms
10,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

constexpr int MOD = 1000000007;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};
mint operator "" _m(unsigned long long n) { return n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[-n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

int main() {
  int N, K; cin >> N >> K;
  vector<mint> dp(N);
  vector<bool> used(N);
  for (int i = 1; i < N; i++) {
    if (N % i == 0 && K % (N / i) == 0) {
      dp[i] = C(i, K / (N / i));
      used[i] = true;
    }
  }
  for (int i = 1; i < N; i++) {
    for (int j = i * 2; j < N; j += i) {
      if (used[j]) {
        dp[j] -= dp[i];
      }
    }
  }
  mint ans;
  for (int i = 1; i < N; i++) {
    ans += dp[i];
  }
  cout << ans << endl;
  /*
  {
  int ans = 0;
  rep(i, 1 << N) {
    if (__builtin_popcount(i) != K) continue;
    int s = i;
    bool any = false;
    rep(j, N - 1) {
      s = (s >> 1) | (s & 1) << N - 1;
      if (s == i) any = true;
    }
    ans += any;
  }
  cout << ans << endl;
  }
  */
}
0