結果

問題 No.890 移調の限られた旋法
ユーザー kyort0nkyort0n
提出日時 2019-09-20 21:58:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,800 bytes
コンパイル時間 2,235 ms
コンパイル使用メモリ 179,716 KB
実行使用メモリ 237,936 KB
最終ジャッジ日時 2023-10-12 19:04:07
合計ジャッジ時間 11,740 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 186 ms
237,872 KB
testcase_01 AC 187 ms
237,656 KB
testcase_02 AC 186 ms
237,924 KB
testcase_03 AC 187 ms
237,816 KB
testcase_04 AC 186 ms
237,712 KB
testcase_05 WA -
testcase_06 AC 188 ms
237,648 KB
testcase_07 AC 187 ms
237,856 KB
testcase_08 AC 186 ms
237,764 KB
testcase_09 AC 203 ms
237,656 KB
testcase_10 AC 180 ms
237,800 KB
testcase_11 AC 178 ms
237,808 KB
testcase_12 AC 178 ms
237,808 KB
testcase_13 AC 178 ms
237,656 KB
testcase_14 AC 193 ms
237,656 KB
testcase_15 AC 180 ms
237,732 KB
testcase_16 AC 179 ms
237,680 KB
testcase_17 AC 179 ms
237,724 KB
testcase_18 AC 179 ms
237,836 KB
testcase_19 AC 179 ms
237,776 KB
testcase_20 AC 179 ms
237,644 KB
testcase_21 AC 179 ms
237,708 KB
testcase_22 AC 179 ms
237,728 KB
testcase_23 AC 178 ms
237,660 KB
testcase_24 AC 178 ms
237,784 KB
testcase_25 AC 179 ms
237,724 KB
testcase_26 AC 178 ms
237,648 KB
testcase_27 AC 181 ms
237,720 KB
testcase_28 AC 179 ms
237,660 KB
testcase_29 AC 181 ms
237,924 KB
testcase_30 AC 180 ms
237,680 KB
testcase_31 AC 178 ms
237,936 KB
testcase_32 AC 179 ms
237,732 KB
testcase_33 AC 178 ms
237,672 KB
testcase_34 AC 178 ms
237,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];
ll beki(ll a, ll b){
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    const int MAX = 10000002;
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}
ll N, K;
map<ll, ll> mp;

vector<ll> f(ll x) {
    vector<ll> v;
    v.push_back(1);
    for(ll i = 2; i * i <= N; i++) {
        if(x % i != 0) continue;
        v.push_back(i);
        if(i * i != N) v.push_back(N / i);
    }
    sort(v.begin(), v.end());
    return v;
}

vector<ll> g(ll x) {
    vector<ll> ret;
    for(ll i = 2; i * i <= x; i++) {
        if(x % i == 0) {
            ret.push_back(i);
            while(x % i == 0) x /= i;
        }
    }
    if(x != 1) ret.push_back(x);
    return ret;
}

int counter(int a) {
    if(a == 0) return 0;
    return (a & 1) + counter(a >> 1);
}

int main() {
    init_combination();
    cin >> N >> K;
    vector<ll> divisors = f(N);
    ll ans = 0;
    for(auto range : divisors) {
        ll val = N / range;
        if(K % val != 0) continue;
        ll now = combination(range,  K / val);
        mp[range] = now;
        //cerr << val << " " << range << " " << now << endl;
        vector<ll> p = g(range);
        for(int bit = 1; bit < (1 << p.size()); bit++) {
            ll nowrange = range;
            for(int i = 0; i < p.size(); i++) {
                if(bit & (1 << i)) nowrange /= p[i];
            }
            if(counter(bit) & 1) now -= mp[nowrange];
            else now += mp[nowrange];
        }
        now %= mod;
        now += mod;
        now %= mod;
        ans = (ans + now) % mod;
    }
    cout << ans << endl;
    return 0;
}
0