結果

問題 No.890 移調の限られた旋法
ユーザー yakamotoyakamoto
提出日時 2019-09-20 23:36:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 3,823 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 174,760 KB
実行使用メモリ 26,760 KB
最終ジャッジ日時 2023-10-12 22:12:30
合計ジャッジ時間 4,046 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 53 ms
26,760 KB
testcase_14 AC 43 ms
26,400 KB
testcase_15 AC 43 ms
26,504 KB
testcase_16 AC 50 ms
26,636 KB
testcase_17 AC 41 ms
24,284 KB
testcase_18 AC 44 ms
24,192 KB
testcase_19 AC 27 ms
15,208 KB
testcase_20 AC 17 ms
10,852 KB
testcase_21 AC 5 ms
4,744 KB
testcase_22 AC 34 ms
21,224 KB
testcase_23 AC 41 ms
24,868 KB
testcase_24 AC 26 ms
15,652 KB
testcase_25 AC 8 ms
6,088 KB
testcase_26 AC 42 ms
25,444 KB
testcase_27 AC 43 ms
26,036 KB
testcase_28 AC 28 ms
17,768 KB
testcase_29 AC 20 ms
12,668 KB
testcase_30 AC 40 ms
24,440 KB
testcase_31 AC 27 ms
14,944 KB
testcase_32 AC 43 ms
22,684 KB
testcase_33 AC 51 ms
23,828 KB
testcase_34 AC 43 ms
23,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#ifndef SOLUTION_COMMON_H

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using PI = pair<int, int>;
template<class T> using V = vector<T>;
using VI = V<int>;
#define _1 first
#define _2 second

#ifdef MY_DEBUG
# define DEBUG(x) x
#else
# define DEBUG(x)
#endif

template<class T>
inline void debug(T &A) {
  DEBUG(
      for (const auto &a : A) {
        cerr << a << " ";
      }
      cerr << '\n';
  )
}

template<class T, class Func>
inline void debug_with_format(T &A, Func f) {
  DEBUG(
      for (const auto &a : A) {
        cerr << f(a) << " ";
      }
      cerr << '\n';
  )
}

template<class T>
inline void debug_dim2(T &A) {
  DEBUG(
      for (const auto &as : A) {
        debug(as);
      }
  )
}

template<typename ... Args>
inline void debug(const char *format, Args const &... args) {
  DEBUG(
      fprintf(stderr, format, args ...);
      cerr << '\n';
  )
}

template<typename ... Args>
string format(const string &fmt, Args ... args) {
  size_t len = snprintf(nullptr, 0, fmt.c_str(), args ...);
  vector<char> buf(len + 1);
  snprintf(&buf[0], len + 1, fmt.c_str(), args ...);
  return string(&buf[0], &buf[0] + len);
}

template<class T1, class T2>
string fmtP(pair<T1, T2> a) {
  stringstream ss;
  ss << "(" << a._1 << "," << a._2 << ")";
  return ss.str();
}

#define SOLUTION_COMMON_H

#endif //SOLUTION_COMMON_H


int msb(int i) {
  i |= (i >>  1);
  i |= (i >>  2);
  i |= (i >>  4);
  i |= (i >>  8);
  i |= (i >> 16);
  return i - (((unsigned int)i) >> 1);
}

int log2(int x) {
  int i = 0;
  while(x >>= 1) i++;
  return i;
}

int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

VI divisors(int x) {
  VI D, back;
  int rt = (int)sqrt(x);
  for (int d = 1; d <= rt; ++d) {
    if (x % d == 0) {
      D.push_back(d);
      if (d * d != x) back.push_back(x / d);
    }
  }
  D.insert(D.end(), back.rbegin(), back.rend());
  return D;
}

ll pow_mod(ll x, int k, ll m) {
  if (k == 0) return 0;
  else if (k == 1) return x;
  else {
    ll a = pow_mod(x * x % m, k / 2, m);
    if (k % 2 == 1) a = a * x % m;
    return a;
  }
}

//inline void add(ll &a, ll b) {
//  a += b;
//  if (a >= MOD) a -= MOD;
//}
//
//inline void sub(ll &a, ll b) {
//  a += MOD - b;
//  if (a >= MOD) a -= MOD;
//}
//
//inline void mul(ll &a, ll b) {
//  a = a * b % MOD;
//}


class Comb {
public:
  int MOD;
  V<ll> F, I;

  Comb(int N, int MOD): MOD(MOD), F(N + 1), I(N + 1) {
    F[0] = 1;
    for (int i = 1; i <= N; ++i) {
      F[i] = F[i - 1] * i % MOD;
    }

    I[N] = pow_mod(F[N], MOD - 2, MOD);
    for (int i = N - 1; i >= 0; --i) {
      I[i] = I[i + 1] * (i + 1) % MOD;
    }
  }

  static ll pow_mod(ll x, int k, int MOD) {
    ll res = k >= 2 ? pow_mod(x * x % MOD, k / 2, MOD) : 1ll;
    if (k&1) res = res * x % MOD;
    return res;
  };

  ll operator()(int n, int k) {
    if (k < 0 || k > n) return 0ll;
    return F[n] * I[n - k] % MOD * I[k] % MOD;
  };

  ll rev(int x) {
    return F[x - 1] * I[x] % MOD;
  }
};

const int MOD = 1000000007;

class D {
public:
  void solve(std::istream& in, std::ostream& out) {
    int n, k;
    in >> n >> k;
    int g = gcd(n, k);
    Comb c(n, MOD);

    ll ans = 0ll;
    V<ll> dp(n + 1);
    for (int grp = g; grp > 1; --grp) {
      if (g % grp == 0) {
        int d = n/grp;
        dp[d] = (dp[d] + c(n / grp, k / grp)) % MOD;
        ans += dp[d];
        int j = d * 2;
        while(j <= n) {
          dp[j] = (MOD + dp[j] - dp[d]) % MOD;
          j += d;
        }
      }
    }
    debug(dp);
    out << ans % MOD;
  }
};


int main() {
	D solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}
0