結果

問題 No.890 移調の限られた旋法
ユーザー ganariyaganariya
提出日時 2019-09-22 21:45:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,856 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 149,016 KB
実行使用メモリ 11,344 KB
最終ジャッジ日時 2023-10-19 07:24:10
合計ジャッジ時間 6,061 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

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 = 25;

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);
        }
    }

    SHOW_VECTOR(dp);

    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