結果

問題 No.890 移調の限られた旋法
ユーザー yuji9511yuji9511
提出日時 2019-09-20 22:36:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 2,803 bytes
コンパイル時間 1,406 ms
コンパイル使用メモリ 158,216 KB
実行使用メモリ 25,116 KB
最終ジャッジ日時 2023-10-12 20:13:15
合計ジャッジ時間 11,025 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 222 ms
24,732 KB
testcase_01 AC 221 ms
24,208 KB
testcase_02 AC 219 ms
23,900 KB
testcase_03 AC 222 ms
23,580 KB
testcase_04 AC 221 ms
24,800 KB
testcase_05 AC 220 ms
24,044 KB
testcase_06 AC 221 ms
24,452 KB
testcase_07 AC 222 ms
24,728 KB
testcase_08 AC 222 ms
23,772 KB
testcase_09 AC 222 ms
23,580 KB
testcase_10 AC 221 ms
23,572 KB
testcase_11 AC 222 ms
24,788 KB
testcase_12 AC 221 ms
23,516 KB
testcase_13 AC 222 ms
23,684 KB
testcase_14 AC 223 ms
24,764 KB
testcase_15 AC 223 ms
24,192 KB
testcase_16 AC 219 ms
24,256 KB
testcase_17 AC 222 ms
23,568 KB
testcase_18 AC 222 ms
24,056 KB
testcase_19 AC 222 ms
23,548 KB
testcase_20 AC 225 ms
23,372 KB
testcase_21 AC 223 ms
23,896 KB
testcase_22 AC 219 ms
23,264 KB
testcase_23 AC 223 ms
23,964 KB
testcase_24 AC 222 ms
23,800 KB
testcase_25 AC 222 ms
25,116 KB
testcase_26 AC 223 ms
23,372 KB
testcase_27 AC 224 ms
23,524 KB
testcase_28 AC 223 ms
23,648 KB
testcase_29 AC 222 ms
23,388 KB
testcase_30 AC 222 ms
23,576 KB
testcase_31 AC 221 ms
24,096 KB
testcase_32 AC 221 ms
23,420 KB
testcase_33 AC 221 ms
23,704 KB
testcase_34 AC 221 ms
23,356 KB
権限があれば一括ダウンロードができます

ソースコード

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(1000010);
	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