結果
問題 | No.890 移調の限られた旋法 |
ユーザー | yuji9511 |
提出日時 | 2019-09-20 22:36:57 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 226 ms / 2,000 ms |
コード長 | 2,803 bytes |
コンパイル時間 | 1,661 ms |
コンパイル使用メモリ | 171,364 KB |
実行使用メモリ | 23,396 KB |
最終ジャッジ日時 | 2024-09-14 18:34:26 |
合計ジャッジ時間 | 10,629 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 224 ms
23,264 KB |
testcase_01 | AC | 223 ms
23,132 KB |
testcase_02 | AC | 223 ms
23,136 KB |
testcase_03 | AC | 224 ms
23,388 KB |
testcase_04 | AC | 224 ms
23,260 KB |
testcase_05 | AC | 225 ms
23,268 KB |
testcase_06 | AC | 224 ms
23,264 KB |
testcase_07 | AC | 225 ms
23,392 KB |
testcase_08 | AC | 223 ms
23,260 KB |
testcase_09 | AC | 224 ms
23,268 KB |
testcase_10 | AC | 223 ms
23,396 KB |
testcase_11 | AC | 224 ms
23,264 KB |
testcase_12 | AC | 224 ms
23,264 KB |
testcase_13 | AC | 223 ms
23,264 KB |
testcase_14 | AC | 225 ms
23,260 KB |
testcase_15 | AC | 223 ms
23,264 KB |
testcase_16 | AC | 224 ms
23,260 KB |
testcase_17 | AC | 225 ms
23,136 KB |
testcase_18 | AC | 224 ms
23,260 KB |
testcase_19 | AC | 224 ms
23,260 KB |
testcase_20 | AC | 226 ms
23,268 KB |
testcase_21 | AC | 224 ms
23,268 KB |
testcase_22 | AC | 224 ms
23,268 KB |
testcase_23 | AC | 224 ms
23,264 KB |
testcase_24 | AC | 224 ms
23,176 KB |
testcase_25 | AC | 224 ms
23,260 KB |
testcase_26 | AC | 223 ms
23,268 KB |
testcase_27 | AC | 224 ms
23,032 KB |
testcase_28 | AC | 223 ms
23,388 KB |
testcase_29 | AC | 223 ms
23,392 KB |
testcase_30 | AC | 224 ms
23,264 KB |
testcase_31 | AC | 224 ms
23,264 KB |
testcase_32 | AC | 224 ms
23,264 KB |
testcase_33 | AC | 224 ms
23,268 KB |
testcase_34 | AC | 225 ms
23,264 KB |
ソースコード
/*** author: yuji9511 ***/ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> lpair; const ll MOD = 1e9 + 7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define print2(x,y) cout << (x) << " " << (y) << endl; #define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];}; struct Integer{ public: ll gcd(ll a,ll b){return b ? gcd(b, a % b) : a;} //最大公約数 ll lcm(ll a,ll b){return a / gcd(a, b) * b;} //最小公倍数 bool isPrime(ll x){ if(x < 2) return false; if(x == 2) return true; if(x % 2 == 0) return false; for(ll i = 3;i <= sqrt(x) + 1;i += 2) if(x % i == 0) return false; return true; } vector<ll> divisor(ll M){ //約数の全列挙 vector<ll> dd; for(ll i = 1; i * i <= M; i++){ if(M % i == 0){ dd.push_back(i); if(i * i != M){ dd.push_back(M / i); } } } sort(dd.begin(), dd.end()); return dd; } vector<ll> factor(ll M){ //素因数分解 vector<ll> dd; if(M == 1){ dd.push_back(1); return dd; } for(ll i = 2; i*i <= M; i++){ while(M % i == 0){ dd.push_back(i); M /= i; } } if(M != 1) dd.push_back(M); sort(dd.begin(), dd.end()); return dd; } }; struct Combination{ private: ll N; vector<ll> fac, facinv; public: Combination(ll n){ N = n; fac.push_back(1); fac.push_back(1); rep(i,2,N+1) fac.push_back(fac[i-1] * i % MOD); rep(i,0,N+1) facinv.push_back(power(fac[i], MOD-2)); } ll power(ll x, ll n){ if(n == 0) return 1LL; ll res = power(x * x % MOD, n/2); if(n % 2 == 1) res = res * x % MOD; return res; } ll nck(ll n, ll k){ if(k == 0 || n == k) return 1LL; return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD; } ll npk(ll n, ll k){ if(k == 0 || n == k) return 1LL; return fac[n] * facinv[n-k] % MOD; } ll get(ll x){return fac[x];}; ll getinv(ll x){return facinv[x];}; }; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N,K; cin >> N >> K; Integer it; Combination cb(1000010); map<ll,ll> mp; if(it.gcd(N,K) == 1 || K == 1){ print(0); }else{ ll ans = 0; vector<ll> dd = it.divisor(N); for(auto &e: dd){ if(e == N) continue; ll num = N / e; if(K % num != 0) continue; ll alt = K / num; ll p = cb.nck(e, alt); for(auto &f: dd){ if(f < e && e % f == 0){ p -= mp[f]; p = (p + MOD) % MOD; } } mp[e] = p; ans += p; ans %= MOD; } print(ans); } }