結果

問題 No.890 移調の限られた旋法
ユーザー mtsd
提出日時 2019-09-20 21:56:56
言語 C++14
(gcc 9.2.0)
結果
AC  
実行時間 84 ms
コード長 1,892 Byte
コンパイル時間 988 ms
使用メモリ 26,968 KB
最終ジャッジ日時 2020-01-28 01:05:43

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
0_sample01.txt AC 68 ms
26,660 KB
0_sample02.txt AC 68 ms
26,808 KB
0_sample03.txt AC 68 ms
26,688 KB
1_small01.txt AC 68 ms
26,676 KB
1_small02.txt AC 68 ms
26,808 KB
1_small03.txt AC 72 ms
26,652 KB
1_small04.txt AC 76 ms
26,704 KB
1_small05.txt AC 72 ms
26,804 KB
1_small06.txt AC 76 ms
26,720 KB
1_small07.txt AC 76 ms
26,724 KB
1_small08.txt AC 72 ms
26,804 KB
1_small09.txt AC 68 ms
26,844 KB
1_small10.txt AC 68 ms
26,688 KB
2_large01.txt AC 80 ms
26,756 KB
2_large02.txt AC 68 ms
26,648 KB
2_large03.txt AC 80 ms
26,800 KB
2_large04.txt AC 84 ms
26,888 KB
2_large05.txt AC 76 ms
26,748 KB
2_large06.txt AC 84 ms
26,908 KB
2_large07.txt AC 72 ms
26,700 KB
2_large08.txt AC 68 ms
26,804 KB
2_large09.txt AC 72 ms
26,704 KB
2_large10.txt AC 68 ms
26,692 KB
2_large11.txt AC 64 ms
26,688 KB
2_large12.txt AC 68 ms
26,728 KB
2_large13.txt AC 68 ms
26,676 KB
2_large14.txt AC 68 ms
26,708 KB
2_large15.txt AC 68 ms
26,704 KB
2_large16.txt AC 64 ms
26,672 KB
2_large17.txt AC 64 ms
26,684 KB
2_large18.txt AC 76 ms
26,732 KB
2_large19.txt AC 72 ms
26,880 KB
2_large20.txt AC 80 ms
26,968 KB
2_large21.txt AC 80 ms
26,848 KB
2_large22.txt AC 72 ms
26,824 KB
テストケース一括ダウンロード

ソースコード

diff #
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

template<typename T>
vector<T> divisor(T n)
{
    vector<T> res;
    for(T i=1;(long long)i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            if(i != n/i){
                res.push_back(n/i);
            }
        }
    }
    sort(res.rbegin(),res.rend());
    return res;
}
#define MAX_N 2000010
#define MOD 1000000007

int inv[MAX_N],fac[MAX_N],finv[MAX_N];

void make()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i=2;i<MAX_N;i++){
        inv[i] = MOD - (long long)inv[MOD%i] * (MOD/i) % MOD;
        fac[i] = (long long)fac[i-1] * i % MOD;
        finv[i] = (long long)finv[i-1] * inv[i] % MOD;
    }
}

int comb(int a,int b)
{
    if(a < b){
        return 0;
    }
    return fac[a] * ((long long)finv[b] * finv[a-b] % MOD) % MOD;
}
ll dp[2000000]={};
    
int main(){
    make();
    int n,k;
    cin >> n >> k;
    vector<int> res = divisor(n);
    ll sm = 0;
    for(int x:res){
        if(x==1)continue;
        if(k%x==0){
            int c = k/x;
            int p = n/x;
            dp[x] = comb(p,c);
            for(int i=x+x;i<=n;i+=x){
               dp[x] += mod-dp[i];
               dp[x] %= mod;
            }
            sm += dp[x];
            sm %= mod;
        }
    }
    cout << sm << endl;
    return 0;
}
0