結果
問題 | No.890 移調の限られた旋法 |
ユーザー |
|
提出日時 | 2019-09-22 21:46:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 338 ms / 2,000 ms |
コード長 | 2,839 bytes |
コンパイル時間 | 1,616 ms |
コンパイル使用メモリ | 143,424 KB |
最終ジャッジ日時 | 2025-01-07 18:59:57 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
//include //------------------------------------------ #include <vector> #include <list> #include <map> #include <unordered_map> #include <climits> #include <set> #include <unordered_set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <queue> #include <random> #include <complex> #include <regex> #include <locale> #include <random> #include <type_traits> using namespace std; #define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";} #define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}} using LL = long long; //------------------------------------------ //------------------------------------------ constexpr LL mod = 1e9 + 7; constexpr LL MAX_N = 2000200; LL POW_MOD(LL N, LL P, LL M) { LL ret = 1; while (P > 0) { if (P & 1LL) ret = (ret * N) % M; N = (N * N) % M; P >>= 1LL; } return ret; } LL fac[MAX_N]; LL inv[MAX_N]; void setup() { fac[0] = fac[1] = 1; inv[0] = inv[1] = 1; for (LL i = 2; i < MAX_N; i++) { fac[i] = fac[i - 1] * i; fac[i] %= mod; inv[i] = POW_MOD(fac[i], mod - 2, mod); } } LL nCr_mod(LL n, LL r) { if (r < 0 || r > n) return 0; return fac[n] * inv[r] % mod * inv[n - r] % mod; } template<typename T> vector<T> DIVISOR(T n) { vector<T> v; for (T i = 1; i * i <= n; ++i) { if (n % i == 0) { v.push_back(i); if (i != n / i) { v.push_back(n / i); } } } sort(v.begin(), v.end()); return v; } template<typename T> vector<vector<T>> DIVISOR_ALL(T n) { vector<vector<T>> res(n + 1); for (T i = 1; i <= n; i++) { for (T j = i; j <= n; j += i) { res[j].push_back(i); } } return res; } int main() { setup(); LL N, K; cin >> N >> K; auto divisors = DIVISOR(N); vector<LL> dp(N + 1, 0); // x回回して回転対称 for (auto x: divisors) { LL P = N / x; if (K % P == 0) { dp[x] = nCr_mod(N / P, K / P); } } for (auto x: divisors) { for (LL y = x * 2; y <= N; y += x) { if (N % y == 0) { dp[y] -= dp[x]; dp[y] += mod; dp[y] %= mod; } } } LL ans = 0; for (LL i = 0; i < N; i++) { ans += dp[i]; ans %= mod; } cout << ans << endl; return 0; }