結果
問題 | No.890 移調の限られた旋法 |
ユーザー | polyomino_24 |
提出日時 | 2019-09-20 23:33:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 123 ms / 2,000 ms |
コード長 | 7,020 bytes |
コンパイル時間 | 1,504 ms |
コンパイル使用メモリ | 137,964 KB |
実行使用メモリ | 50,432 KB |
最終ジャッジ日時 | 2024-09-14 20:23:43 |
合計ジャッジ時間 | 5,478 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 108 ms
50,304 KB |
testcase_01 | AC | 36 ms
50,176 KB |
testcase_02 | AC | 110 ms
50,176 KB |
testcase_03 | AC | 108 ms
50,176 KB |
testcase_04 | AC | 109 ms
50,304 KB |
testcase_05 | AC | 36 ms
50,176 KB |
testcase_06 | AC | 109 ms
50,304 KB |
testcase_07 | AC | 36 ms
50,432 KB |
testcase_08 | AC | 36 ms
50,176 KB |
testcase_09 | AC | 111 ms
50,304 KB |
testcase_10 | AC | 36 ms
50,304 KB |
testcase_11 | AC | 36 ms
50,176 KB |
testcase_12 | AC | 113 ms
50,304 KB |
testcase_13 | AC | 107 ms
50,304 KB |
testcase_14 | AC | 36 ms
50,176 KB |
testcase_15 | AC | 110 ms
50,176 KB |
testcase_16 | AC | 116 ms
50,304 KB |
testcase_17 | AC | 117 ms
50,176 KB |
testcase_18 | AC | 123 ms
50,176 KB |
testcase_19 | AC | 106 ms
50,304 KB |
testcase_20 | AC | 35 ms
50,304 KB |
testcase_21 | AC | 36 ms
50,432 KB |
testcase_22 | AC | 105 ms
50,176 KB |
testcase_23 | AC | 35 ms
50,304 KB |
testcase_24 | AC | 107 ms
50,176 KB |
testcase_25 | AC | 36 ms
50,176 KB |
testcase_26 | AC | 109 ms
50,304 KB |
testcase_27 | AC | 107 ms
50,304 KB |
testcase_28 | AC | 36 ms
50,176 KB |
testcase_29 | AC | 109 ms
50,432 KB |
testcase_30 | AC | 110 ms
50,304 KB |
testcase_31 | AC | 109 ms
50,304 KB |
testcase_32 | AC | 109 ms
50,304 KB |
testcase_33 | AC | 108 ms
50,304 KB |
testcase_34 | AC | 106 ms
50,304 KB |
ソースコード
#include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) //#define cerr if(false) cerr #ifdef DEBUG #define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__); #else #define show(...) 42 #endif using namespace std; using ll = long long; using pii = pair<int, int>; template <typename T, typename S> ostream& operator<<(ostream& os, pair<T, S> a) { os << '(' << a.first << ',' << a.second << ')'; return os; } template <typename T> ostream& operator<<(ostream& os, vector<T> v) { for (auto x : v) os << x << ' '; return os; } void debug() { cerr << '\n'; } template <typename H, typename... T> void debug(H a, T... b) { cerr << a; if (sizeof...(b)) cerr << ", "; debug(b...); } template <typename T> vector<T> divisor(T n) { vector<T> res; for (T i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (i * i != n) { res.push_back(n / i); } } } sort(res.begin(), res.end()); return res; } template <typename T> map<T, int> prime_factor(T n) { map<T, int> res; for (T i = 2; i * i <= n; i++) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) { res[n]++; } return res; } template <typename T> T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } //負の数を掛けたりするとバグる template<int MOD> class Modint{ public: int a; Modint(const long long v = 0):a(v % MOD){} int getmod() const{ return MOD; } Modint operator+(const Modint rhs) const{ return Modint(*this) += rhs; } Modint operator-(const Modint rhs) const{ return Modint(*this) -= rhs; } Modint operator*(const Modint rhs) const{ return Modint(*this) *= rhs; } Modint operator/(const Modint rhs) const{ return Modint(*this) /= rhs; } Modint operator+(const long long rhs) const{ return Modint(*this) += rhs; } Modint operator-(const long long rhs) const{ return Modint(*this) -= rhs; } Modint operator*(const long long rhs) const{ return Modint(*this) *= rhs; } Modint operator/(const long long rhs) const{ return Modint(*this) /= rhs; } friend Modint operator+(const long long a, const Modint b){ return b + a; } friend Modint operator-(const long long a, const Modint b){ return -b + a; } friend Modint operator*(const long long a, const Modint b){ return b * a; } friend Modint operator/(const long long a, const Modint b){ return Modint(a) / b; } Modint &operator+=(const Modint rhs){ a += rhs.a; if(a >= MOD){ a -= MOD; } return *this; } Modint &operator-=(const Modint rhs){ if(a < rhs.a){ a += MOD; } a -= rhs.a; return *this; } Modint &operator*=(const Modint rhs){ a = (long long)a * rhs.a % MOD; return *this; } Modint &operator/=(Modint rhs){ int x = MOD - 2; while(x){ if(x % 2){ *this *= rhs; } rhs *= rhs; x /= 2; } return *this; } Modint &operator++(){ *this += 1; return *this; } Modint &operator--(){ *this -= 1; return *this; } Modint operator++(int){ Modint res = *this; ++(*this); return res; } Modint operator--(int){ Modint res = *this; --(*this); return res; } Modint &operator+=(const long long rhs){ *this += Modint(rhs); return *this; } Modint &operator-=(const long long rhs){ *this -= Modint(rhs); return *this; } Modint &operator*=(const long long rhs){ *this *= Modint(rhs); return *this; } Modint &operator/=(const long long rhs){ *this /= Modint(rhs); return *this; } Modint operator+() const{ return *this; } Modint operator-() const{ return Modint()-*this; } bool operator==(const Modint rhs) const{ return a == rhs.a; } bool operator==(const long long rhs) const{ return a == rhs; } friend bool operator==(const long long a, const Modint b){ return a == b.a; } bool operator!=(const Modint rhs) const{ return a != rhs.a; } bool operator!=(const long long rhs) const{ return a != rhs; } friend ostream &operator<<(ostream &os, const Modint x){ os << x.a; return os; } friend istream &operator>>(istream &is, Modint &x){ is >> x.a; return is; } explicit operator bool() const{ return a > 0; } bool operator!(){ return a == 0; } explicit operator int() const{ return a; } explicit operator long long() const{ return (long long) a; } friend Modint pow(Modint a, long long b){ Modint res = 1; while(b){ if(b % 2){ res *= a; } a *= a; b /= 2; } return res; } }; using mint = Modint<1000000007>; const int NUM = 4000005; mint fact[NUM + 1], fact_inv[NUM + 1], inv[NUM + 1]; mint combi(long long N_, long long K_){ static const int Mod_ = fact[0].getmod(); if(fact[0] == 0){ inv[1] = fact[0] = fact_inv[0] = 1; for(int i = 2; i <= NUM; i++){ inv[i] = inv[Mod_ % i] * (Mod_ - Mod_ / i); } for(int i = 1; i <= NUM; i++){ fact[i] = fact[i - 1] * i; fact_inv[i] = fact_inv[i - 1] * inv[i]; } } if(K_ < 0 or K_ > N_) return 0; return fact_inv[K_] * fact[N_] * fact_inv[N_ - K_]; } mint hcomb(long long N_, long long K_){ return ((N_ | K_) == 0) ? 1 : combi(N_ + K_ - 1, K_); } int main(){ int n, k; cin >> n >> k; auto d = divisor(n); mint ans = 0; bool f = true; for(int x : d){ if(x == 1)continue; if(k % x)continue; int l = k / x; auto hoge = prime_factor(x); f = hoge.size() % 2; bool dame = false; for(auto aa:hoge)if(aa.second >1)dame = true; if(dame)continue; f = prime_factor(x).size() % 2; show(x, n/x, l, combi(n/x,l)); if(f)ans += combi(n/x, l); else ans -= combi(n/x, l); } cout << ans << endl; }