結果
問題 | No.890 移調の限られた旋法 |
ユーザー | 👑 emthrm |
提出日時 | 2019-09-21 06:06:29 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 2,292 bytes |
コンパイル時間 | 1,074 ms |
コンパイル使用メモリ | 119,456 KB |
実行使用メモリ | 27,564 KB |
最終ジャッジ日時 | 2023-10-14 11:00:44 |
合計ジャッジ時間 | 3,112 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,484 KB |
testcase_01 | AC | 2 ms
5,440 KB |
testcase_02 | AC | 2 ms
5,472 KB |
testcase_03 | AC | 2 ms
5,368 KB |
testcase_04 | AC | 2 ms
5,472 KB |
testcase_05 | AC | 1 ms
5,288 KB |
testcase_06 | AC | 2 ms
5,404 KB |
testcase_07 | AC | 2 ms
5,272 KB |
testcase_08 | AC | 2 ms
5,464 KB |
testcase_09 | AC | 1 ms
5,448 KB |
testcase_10 | AC | 1 ms
5,476 KB |
testcase_11 | AC | 1 ms
5,476 KB |
testcase_12 | AC | 2 ms
5,528 KB |
testcase_13 | AC | 55 ms
27,384 KB |
testcase_14 | AC | 52 ms
27,564 KB |
testcase_15 | AC | 50 ms
27,392 KB |
testcase_16 | AC | 53 ms
27,384 KB |
testcase_17 | AC | 46 ms
26,708 KB |
testcase_18 | AC | 48 ms
26,768 KB |
testcase_19 | AC | 30 ms
19,376 KB |
testcase_20 | AC | 19 ms
13,892 KB |
testcase_21 | AC | 5 ms
6,000 KB |
testcase_22 | AC | 40 ms
23,332 KB |
testcase_23 | AC | 47 ms
26,996 KB |
testcase_24 | AC | 29 ms
19,508 KB |
testcase_25 | AC | 9 ms
7,192 KB |
testcase_26 | AC | 47 ms
27,168 KB |
testcase_27 | AC | 49 ms
27,300 KB |
testcase_28 | AC | 33 ms
20,140 KB |
testcase_29 | AC | 22 ms
14,248 KB |
testcase_30 | AC | 45 ms
26,600 KB |
testcase_31 | AC | 29 ms
17,216 KB |
testcase_32 | AC | 46 ms
26,224 KB |
testcase_33 | AC | 53 ms
26,688 KB |
testcase_34 | AC | 47 ms
26,468 KB |
ソースコード
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #define _USE_MATH_DEFINES #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; /*-------------------------------------------------*/ long long mod_inv(long long a, long long mod = MOD) { a %= mod; if (__gcd(a, mod) != 1) return -1; long long b = mod, x = 1, y = 0; while (b > 0) { long long tmp = a / b; a -= tmp * b; swap(a, b); x -= tmp * y; swap(x, y); } x %= mod; if (x < 0) x += mod; return x; } const int MAX = 10000000; long long fact[MAX + 1], fact_inv[MAX + 1]; void nCk_init(int val = MAX, long long mod = MOD) { fact[0] = 1; FOR(i, 1, val + 1) fact[i] = fact[i - 1] * i % mod; fact_inv[val] = mod_inv(fact[val], mod); for (int i = val; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i % mod; } long long nCk(int n, int k, long long mod = MOD) { if (n < 0 || n < k || k < 0) return 0; return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int n, k; cin >> n >> k; nCk_init(n); vector<long long> dp(n + 1, 0); vector<bool> ok(n + 1, false); FOR(i, 1, n) { if (n % i == 0) { int t = n / __gcd(i, n); if (k % t == 0) { (dp[i] = nCk(n / t, k / t)) %= MOD; ok[i] = true; } } } FOR(i, 1, n + 1) if (ok[i]) { for (int j = i * 2; j <= n; j += i) { if (ok[j]) (dp[j] += MOD - dp[i]) %= MOD; } } long long ans = 0; FOR(i, 1, n + 1) (ans += dp[i]) %= MOD; cout << ans << '\n'; return 0; }