結果

問題 No.890 移調の限られた旋法
ユーザー erbowlerbowl
提出日時 2020-03-20 18:45:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,706 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 181,388 KB
実行使用メモリ 34,608 KB
最終ジャッジ日時 2024-05-08 10:32:17
合計ジャッジ時間 4,045 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
27,016 KB
testcase_01 AC 24 ms
26,932 KB
testcase_02 AC 24 ms
26,960 KB
testcase_03 AC 25 ms
26,800 KB
testcase_04 AC 25 ms
27,012 KB
testcase_05 WA -
testcase_06 AC 24 ms
26,856 KB
testcase_07 AC 23 ms
26,924 KB
testcase_08 AC 23 ms
26,884 KB
testcase_09 AC 23 ms
26,964 KB
testcase_10 AC 24 ms
26,872 KB
testcase_11 AC 23 ms
26,868 KB
testcase_12 AC 24 ms
26,768 KB
testcase_13 AC 45 ms
34,540 KB
testcase_14 AC 48 ms
34,404 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 31 ms
29,332 KB
testcase_21 AC 24 ms
27,160 KB
testcase_22 WA -
testcase_23 AC 44 ms
33,996 KB
testcase_24 AC 34 ms
30,900 KB
testcase_25 AC 27 ms
27,576 KB
testcase_26 WA -
testcase_27 AC 43 ms
34,240 KB
testcase_28 AC 38 ms
31,552 KB
testcase_29 AC 31 ms
29,872 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 48 ms
33,600 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

const int MAX = 1000010;
const int MOD = 1000000007;
 
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;
     }
 }
 
 // 二項係数計算
 long long COM(int n, int k){
     if (n < k) return 0;
     if (n < 0 || k < 0) return 0;
     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
 }

int main() {
    ll n,k;
    COMinit();
    std::cin >> n>>k;
    vector<ll> prime(n+1,1);
    prime[0] = prime[1] = 0;
    
    for (int i = 1; i < n+1; i++) {
        if(prime[i]==1){
            for(int j = i + i; j < n+1; j+=i){
                prime[j] = i;
            }
        }
    }
    map<ll,ll> memo;
    ll ans = 0;
    for (int i = 2; i < n; i++) {
        if(n%i==0&&k%(n/i)==0){
            memo[i]=COM(i,k/(n/i));
            if(prime[i]==1){
                ans += memo[i];
            }else{
                ans += memo[i];
                ll tmp = i;
                set<ll> s;
                while(prime[tmp]>1){
                    s.insert(prime[tmp]);
                    tmp/=prime[tmp];
                }
                if(tmp!=1){
                    s.insert(tmp);
                }
                for (auto e : s) {
                    ans -= memo[e];
                }
            }
        }
    }
    if(n==k){
        std::cout << 1 << std::endl;
        return 0;
    }
    
    std::cout << ans << std::endl;
}
0