結果
問題 | No.890 移調の限られた旋法 |
ユーザー | 👑 jupiro |
提出日時 | 2020-01-28 18:35:01 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 337 ms / 2,000 ms |
コード長 | 2,738 bytes |
コンパイル時間 | 998 ms |
コンパイル使用メモリ | 114,732 KB |
実行使用メモリ | 130,648 KB |
最終ジャッジ日時 | 2023-10-13 20:50:07 |
合計ジャッジ時間 | 13,130 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 320 ms
122,948 KB |
testcase_01 | AC | 275 ms
123,232 KB |
testcase_02 | AC | 298 ms
122,920 KB |
testcase_03 | AC | 287 ms
123,112 KB |
testcase_04 | AC | 289 ms
122,996 KB |
testcase_05 | AC | 280 ms
122,912 KB |
testcase_06 | AC | 277 ms
122,980 KB |
testcase_07 | AC | 267 ms
122,932 KB |
testcase_08 | AC | 271 ms
122,920 KB |
testcase_09 | AC | 280 ms
123,200 KB |
testcase_10 | AC | 272 ms
123,112 KB |
testcase_11 | AC | 276 ms
123,100 KB |
testcase_12 | AC | 278 ms
122,980 KB |
testcase_13 | AC | 305 ms
130,392 KB |
testcase_14 | AC | 305 ms
130,648 KB |
testcase_15 | AC | 321 ms
130,408 KB |
testcase_16 | AC | 311 ms
130,448 KB |
testcase_17 | AC | 305 ms
129,696 KB |
testcase_18 | AC | 337 ms
129,640 KB |
testcase_19 | AC | 310 ms
126,800 KB |
testcase_20 | AC | 292 ms
125,120 KB |
testcase_21 | AC | 295 ms
123,004 KB |
testcase_22 | AC | 299 ms
128,780 KB |
testcase_23 | AC | 291 ms
130,000 KB |
testcase_24 | AC | 289 ms
126,748 KB |
testcase_25 | AC | 277 ms
123,612 KB |
testcase_26 | AC | 310 ms
130,152 KB |
testcase_27 | AC | 312 ms
130,224 KB |
testcase_28 | AC | 297 ms
127,536 KB |
testcase_29 | AC | 285 ms
125,584 KB |
testcase_30 | AC | 303 ms
129,672 KB |
testcase_31 | AC | 298 ms
126,852 KB |
testcase_32 | AC | 311 ms
129,092 KB |
testcase_33 | AC | 313 ms
129,456 KB |
testcase_34 | AC | 319 ms
129,340 KB |
ソースコード
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; struct mint { ll x; // typedef long long ll; mint(ll x = 0) :x((x% mod + mod) % mod) {} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } mint COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return mint(fac[n] * (finv[k] * finv[n - k] % mod) % mod); } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ COMinit(); ll n, k; scanf("%lld %lld", &n, &k); vector<mint> dp(n + 1); for (ll i = 1; i < n; i++) { if (n % i == 0) { ll p = n / i; if (k % p == 0) dp[i] = COM(n / p, k / p); } } mint res = 0; for (ll i = 1; i < n; i++) { if (dp[i].x == 0) continue; for (ll j = 2; j * i < n; j++) { if(n % (i * j) == 0 ) dp[i * j] -= dp[i]; } } for (ll i = 1; i < n; i++) { //cout << dp[i].x << endl; if(n % i == 0) res += dp[i]; } cout << res.x << endl; return 0; }