結果

問題 No.890 移調の限られた旋法
ユーザー ganariyaganariya
提出日時 2019-09-22 21:46:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 390 ms / 2,000 ms
コード長 2,839 bytes
コンパイル時間 1,535 ms
コンパイル使用メモリ 148,824 KB
実行使用メモリ 42,548 KB
最終ジャッジ日時 2023-10-19 07:24:36
合計ジャッジ時間 15,479 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 341 ms
35,092 KB
testcase_01 AC 341 ms
35,092 KB
testcase_02 AC 341 ms
35,092 KB
testcase_03 AC 341 ms
35,092 KB
testcase_04 AC 341 ms
35,092 KB
testcase_05 AC 340 ms
35,092 KB
testcase_06 AC 341 ms
35,092 KB
testcase_07 AC 342 ms
35,092 KB
testcase_08 AC 342 ms
35,092 KB
testcase_09 AC 339 ms
35,092 KB
testcase_10 AC 344 ms
35,092 KB
testcase_11 AC 342 ms
35,092 KB
testcase_12 AC 342 ms
35,092 KB
testcase_13 AC 374 ms
42,548 KB
testcase_14 AC 376 ms
42,548 KB
testcase_15 AC 375 ms
42,548 KB
testcase_16 AC 375 ms
42,548 KB
testcase_17 AC 383 ms
41,824 KB
testcase_18 AC 382 ms
41,824 KB
testcase_19 AC 357 ms
38,988 KB
testcase_20 AC 350 ms
37,472 KB
testcase_21 AC 343 ms
35,360 KB
testcase_22 AC 363 ms
40,768 KB
testcase_23 AC 365 ms
42,088 KB
testcase_24 AC 358 ms
38,988 KB
testcase_25 AC 345 ms
35,624 KB
testcase_26 AC 376 ms
42,352 KB
testcase_27 AC 363 ms
42,284 KB
testcase_28 AC 357 ms
39,780 KB
testcase_29 AC 354 ms
38,000 KB
testcase_30 AC 390 ms
41,824 KB
testcase_31 AC 364 ms
38,724 KB
testcase_32 AC 387 ms
41,296 KB
testcase_33 AC 380 ms
41,560 KB
testcase_34 AC 379 ms
41,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------

constexpr LL mod = 1e9 + 7;
constexpr LL MAX_N = 2000200;

LL POW_MOD(LL N, LL P, LL M) {
    LL ret = 1;
    while (P > 0) {
        if (P & 1LL) ret = (ret * N) % M;
        N = (N * N) % M;
        P >>= 1LL;
    }
    return ret;
}

LL fac[MAX_N];
LL inv[MAX_N];

void setup() {
    fac[0] = fac[1] = 1;
    inv[0] = inv[1] = 1;
    for (LL i = 2; i < MAX_N; i++) {
        fac[i] = fac[i - 1] * i;
        fac[i] %= mod;
        inv[i] = POW_MOD(fac[i], mod - 2, mod);
    }
}

LL nCr_mod(LL n, LL r) {
    if (r < 0 || r > n) return 0;
    return fac[n] * inv[r] % mod * inv[n - r] % mod;
}

template<typename T>
vector<T> DIVISOR(T n) {
    vector<T> v;
    for (T i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            v.push_back(i);
            if (i != n / i) {
                v.push_back(n / i);
            }
        }
    }
    sort(v.begin(), v.end());
    return v;
}

template<typename T>
vector<vector<T>> DIVISOR_ALL(T n) {
    vector<vector<T>> res(n + 1);
    for (T i = 1; i <= n; i++) {
        for (T j = i; j <= n; j += i) {
            res[j].push_back(i);
        }
    }
    return res;
}

int main() {

    setup();

    LL N, K;
    cin >> N >> K;

    auto divisors = DIVISOR(N);
    vector<LL> dp(N + 1, 0);

    // x回回して回転対称
    for (auto x: divisors) {
        LL P = N / x;
        if (K % P == 0) {
            dp[x] = nCr_mod(N / P, K / P);
        }
    }

    for (auto x: divisors) {
        for (LL y = x * 2; y <= N; y += x) {
            if (N % y == 0) {
                dp[y] -= dp[x];
                dp[y] += mod;
                dp[y] %= mod;
            }
        }
    }

    LL ans = 0;
    for (LL i = 0; i < N; i++) {
        ans += dp[i];
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}


































0