結果
問題 | No.890 移調の限られた旋法 |
ユーザー | ゆきのん |
提出日時 | 2019-09-20 23:14:11 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 2,011 bytes |
コンパイル時間 | 3,039 ms |
コンパイル使用メモリ | 174,284 KB |
実行使用メモリ | 37,176 KB |
最終ジャッジ日時 | 2023-10-12 21:44:46 |
合計ジャッジ時間 | 4,944 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
35,712 KB |
testcase_01 | AC | 39 ms
36,596 KB |
testcase_02 | AC | 39 ms
36,560 KB |
testcase_03 | AC | 40 ms
35,656 KB |
testcase_04 | AC | 38 ms
36,184 KB |
testcase_05 | AC | 39 ms
36,220 KB |
testcase_06 | AC | 40 ms
37,176 KB |
testcase_07 | AC | 40 ms
36,872 KB |
testcase_08 | AC | 40 ms
35,776 KB |
testcase_09 | AC | 40 ms
36,740 KB |
testcase_10 | AC | 39 ms
36,332 KB |
testcase_11 | AC | 40 ms
35,468 KB |
testcase_12 | AC | 39 ms
36,416 KB |
testcase_13 | AC | 40 ms
36,928 KB |
testcase_14 | AC | 38 ms
35,464 KB |
testcase_15 | AC | 38 ms
35,724 KB |
testcase_16 | AC | 39 ms
35,512 KB |
testcase_17 | AC | 39 ms
35,868 KB |
testcase_18 | AC | 38 ms
36,392 KB |
testcase_19 | AC | 40 ms
36,972 KB |
testcase_20 | AC | 39 ms
35,400 KB |
testcase_21 | AC | 38 ms
35,268 KB |
testcase_22 | AC | 39 ms
35,224 KB |
testcase_23 | AC | 39 ms
35,968 KB |
testcase_24 | AC | 38 ms
35,644 KB |
testcase_25 | AC | 38 ms
35,084 KB |
testcase_26 | AC | 38 ms
35,532 KB |
testcase_27 | AC | 39 ms
35,692 KB |
testcase_28 | AC | 38 ms
36,204 KB |
testcase_29 | AC | 40 ms
36,556 KB |
testcase_30 | AC | 40 ms
35,928 KB |
testcase_31 | AC | 41 ms
36,700 KB |
testcase_32 | AC | 40 ms
35,524 KB |
testcase_33 | AC | 39 ms
35,220 KB |
testcase_34 | AC | 39 ms
36,136 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long LL; typedef pair<int,int> P; const LL mod=1000000007; const LL LINF=1LL<<60; const int INF=1<<30; vector<LL> fact; vector<LL> inver(2000001); LL combi(int n,int r){ if(n<r||n<0||r<0) return 0; return fact[n]%mod*inver[n-r]%mod*inver[r]%mod; } LL fpow(LL a, LL n){ LL x = 1; while(n > 0){ if(n&1){ x=x*a%mod; } a=a*a%mod; n >>= 1; } return x; } void set_combi(){ LL s=1; fact.push_back(1); for(int i=1;i<=2000000;i++){ s*=i; s%=mod; fact.push_back(s); } inver[2000000]=fpow(fact[2000000],mod-2); for(int i=1999999;i>=0;i--){ inver[i]=inver[i+1]*(i+1)%mod; } } vector<LL> divi(LL K){ vector<LL> v; for(int i=1;i*i<=K;i++){ if(K%i) continue; v.pb(i); v.pb(K/i); } sort(ALL(v)); v.erase(unique(ALL(v)),v.end()); return v; } LL gcd(LL a,LL b){ if(b>a) swap(a,b); if(a%b==0) return b; return gcd(b,a%b); } vector<LL> pdivi(LL K){ vector<LL> v; for(int i=2;i*i<=K;i++){ if(K%i) continue; v.pb(i); while(K%i==0){ K/=i; } } if(K!=1) v.pb(K); return v; } int main(){ LL n,k;cin >> n >> k; set_combi(); LL a = gcd(n,k); auto p = pdivi(a); LL ans = 0; for (int i = 1; i < (1<<p.size()); i++) { int count = 0; LL s=n,t=k; for (int j = 0; j < p.size(); j++) { if(i>>j&1){ count++; s/=p[j]; t/=p[j]; } } if(count%2){ ans = (ans + combi(s,t)) % mod; } else{ ans = (ans - combi(s,t) + mod) % mod; } } cout << ans << endl; return 0; }