結果

問題 No.890 移調の限られた旋法
ユーザー yuji9511yuji9511
提出日時 2019-09-20 22:35:28
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,802 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 158,196 KB
実行使用メモリ 5,716 KB
最終ジャッジ日時 2023-10-12 20:10:27
合計ジャッジ時間 6,179 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
5,536 KB
testcase_01 AC 25 ms
5,468 KB
testcase_02 AC 25 ms
5,316 KB
testcase_03 AC 24 ms
5,524 KB
testcase_04 AC 25 ms
5,332 KB
testcase_05 AC 25 ms
5,400 KB
testcase_06 AC 25 ms
5,472 KB
testcase_07 AC 25 ms
5,344 KB
testcase_08 AC 25 ms
5,476 KB
testcase_09 AC 25 ms
5,600 KB
testcase_10 AC 25 ms
5,336 KB
testcase_11 AC 25 ms
5,352 KB
testcase_12 AC 25 ms
5,604 KB
testcase_13 AC 25 ms
5,340 KB
testcase_14 AC 25 ms
5,472 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 25 ms
5,328 KB
testcase_21 AC 25 ms
5,336 KB
testcase_22 RE -
testcase_23 AC 25 ms
5,472 KB
testcase_24 RE -
testcase_25 AC 25 ms
5,484 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 26 ms
5,320 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 25 ms
5,520 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
struct Integer{
public:

    ll gcd(ll a,ll b){return b ? gcd(b, a % b) : a;} //最大公約数

    ll lcm(ll a,ll b){return a / gcd(a, b) * b;} //最小公倍数

    bool isPrime(ll x){
        if(x < 2) return false;
        if(x == 2) return true;
        if(x % 2 == 0) return false;
        for(ll i = 3;i <= sqrt(x) + 1;i += 2) if(x % i == 0) return false;
        return true;
    }

    vector<ll> divisor(ll M){ //約数の全列挙
        vector<ll> dd;
        for(ll i = 1; i * i <= M; i++){
            if(M % i == 0){
                dd.push_back(i);
                if(i * i != M){
                    dd.push_back(M / i);
                }
            }
        }
        sort(dd.begin(), dd.end());
        return dd;
    }

    vector<ll> factor(ll M){ //素因数分解
        vector<ll> dd;
        if(M == 1){
            dd.push_back(1);
            return dd;
        }
        for(ll i = 2; i*i <= M; i++){
            while(M % i == 0){
                dd.push_back(i);
                M /= i;
            }
        }
        if(M != 1) dd.push_back(M);
        sort(dd.begin(), dd.end());
        return dd;
    }
};

struct Combination{
private:
	ll N;
	vector<ll> fac, facinv;

public:
	Combination(ll n){
		N = n;
		fac.push_back(1); fac.push_back(1);
		rep(i,2,N+1) fac.push_back(fac[i-1] * i % MOD);
		rep(i,0,N+1) facinv.push_back(power(fac[i], MOD-2));
	}
	ll power(ll x, ll n){
		if(n == 0) return 1LL;
		ll res = power(x * x % MOD, n/2);
		if(n % 2 == 1) res = res * x % MOD;
		return res;
	}
	ll nck(ll n, ll k){
		if(k == 0 || n == k) return 1LL;
		return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD;
	}
	ll npk(ll n, ll k){
		if(k == 0 || n == k) return 1LL;
		return fac[n] * facinv[n-k] % MOD;
	}
	ll get(ll x){return fac[x];};
	ll getinv(ll x){return facinv[x];};
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,K;
	cin >> N >> K;
	Integer it;
	Combination cb(100010);
	map<ll,ll> mp;
	if(it.gcd(N,K) == 1 || K == 1){
		print(0);
	}else{
		ll ans = 0;
		vector<ll> dd = it.divisor(N);
		for(auto &e: dd){
			if(e == N) continue;
			ll num = N / e;
			if(K % num != 0) continue;
			ll alt = K / num;
			ll p = cb.nck(e, alt);
			for(auto &f: dd){
				if(f < e && e % f == 0){
					p -= mp[f];
					p = (p + MOD) % MOD;
				}
			}
			mp[e] = p;
			ans += p;
			ans %= MOD;
		}
		print(ans);

	}
	
}
0