結果

問題 No.890 移調の限られた旋法
ユーザー tactac
提出日時 2019-09-21 14:40:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 2,083 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 168,180 KB
実行使用メモリ 20,952 KB
最終ジャッジ日時 2023-10-19 02:23:02
合計ジャッジ時間 3,761 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
16,656 KB
testcase_01 AC 13 ms
16,656 KB
testcase_02 AC 13 ms
16,656 KB
testcase_03 AC 13 ms
16,656 KB
testcase_04 AC 13 ms
16,656 KB
testcase_05 AC 13 ms
16,656 KB
testcase_06 AC 12 ms
16,656 KB
testcase_07 AC 13 ms
16,656 KB
testcase_08 AC 13 ms
16,656 KB
testcase_09 AC 13 ms
16,656 KB
testcase_10 AC 13 ms
16,656 KB
testcase_11 AC 13 ms
16,656 KB
testcase_12 AC 13 ms
16,656 KB
testcase_13 AC 22 ms
20,828 KB
testcase_14 AC 18 ms
16,656 KB
testcase_15 AC 19 ms
20,792 KB
testcase_16 AC 23 ms
20,820 KB
testcase_17 AC 19 ms
20,816 KB
testcase_18 AC 21 ms
20,852 KB
testcase_19 AC 18 ms
18,740 KB
testcase_20 AC 14 ms
16,656 KB
testcase_21 AC 14 ms
16,656 KB
testcase_22 AC 17 ms
20,756 KB
testcase_23 AC 17 ms
16,656 KB
testcase_24 AC 16 ms
18,708 KB
testcase_25 AC 14 ms
16,656 KB
testcase_26 AC 18 ms
20,756 KB
testcase_27 AC 18 ms
18,704 KB
testcase_28 AC 16 ms
16,656 KB
testcase_29 AC 15 ms
18,708 KB
testcase_30 AC 19 ms
20,884 KB
testcase_31 AC 17 ms
18,800 KB
testcase_32 AC 22 ms
20,952 KB
testcase_33 AC 21 ms
20,896 KB
testcase_34 AC 21 ms
18,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




const int MAX = 510000;
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 n, k;
ll dp[1010101];

void solve() {
    cin >> n >> k;
    
    rep3(x, 1, n) if (n % x == 0) {
        int p = n / x;
        if (k % p != 0) continue;
        dp[x] = COM(x, k / p);
    }
    // rep3(x, 1, n) cout << dp[x] << " "; cout << endl;
    
    ll ret = 0;
    rep3(x, 1, n) if (dp[x]) {
        ret += dp[x]; // g(x)の総和が解
        // zにとっては約数分を引く
        // ただし, zはnの約数
        // f(z)からg(x)を順次引く -> g(x)を確定
        for (int z = x * 2; z <= n; z += x) if (n % z == 0) (dp[z] += MOD - dp[x]) %= MOD;
    }
    // rep3(x, 1, n) cout << dp[x] << " "; cout << endl;
    
    cout << ret % MOD << endl;
}

int main() {
    
    COMinit();
    
    solve();
    
    
}
0