結果

問題 No.890 移調の限られた旋法
ユーザー pockynypockyny
提出日時 2019-09-20 22:41:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 974 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 80,752 KB
実行使用メモリ 30,916 KB
最終ジャッジ日時 2023-10-12 20:20:40
合計ジャッジ時間 4,206 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
28,468 KB
testcase_01 AC 56 ms
28,516 KB
testcase_02 AC 57 ms
28,544 KB
testcase_03 AC 56 ms
28,468 KB
testcase_04 AC 56 ms
28,676 KB
testcase_05 AC 57 ms
28,672 KB
testcase_06 WA -
testcase_07 AC 57 ms
28,468 KB
testcase_08 AC 57 ms
28,616 KB
testcase_09 AC 57 ms
28,460 KB
testcase_10 AC 57 ms
28,480 KB
testcase_11 AC 58 ms
28,460 KB
testcase_12 AC 57 ms
28,748 KB
testcase_13 AC 72 ms
30,872 KB
testcase_14 AC 57 ms
28,612 KB
testcase_15 AC 71 ms
30,624 KB
testcase_16 AC 73 ms
30,604 KB
testcase_17 AC 72 ms
30,600 KB
testcase_18 AC 79 ms
30,628 KB
testcase_19 AC 63 ms
30,548 KB
testcase_20 AC 57 ms
28,780 KB
testcase_21 AC 57 ms
28,464 KB
testcase_22 AC 64 ms
30,576 KB
testcase_23 AC 57 ms
28,460 KB
testcase_24 AC 61 ms
30,504 KB
testcase_25 AC 57 ms
28,528 KB
testcase_26 AC 69 ms
30,520 KB
testcase_27 AC 60 ms
28,488 KB
testcase_28 AC 58 ms
28,468 KB
testcase_29 AC 59 ms
28,612 KB
testcase_30 AC 78 ms
30,800 KB
testcase_31 AC 64 ms
28,568 KB
testcase_32 AC 87 ms
30,728 KB
testcase_33 WA -
testcase_34 AC 73 ms
30,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAX = 1000010;
ll inv[MAX],fact[MAX],fi[MAX],mod = 1000000007;
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}
ll ans = 0,cnt[1000010] = {};
vector<ll> v;
int main(){
	int i,j,n,k;
	cin >> n >> k;
	for(i=2;i*i<=n;i++){
		if(n%i==0){
			v.push_back(i);
			if(i*i!=n){
				v.push_back(n/i);
			}
		}
	}
	inverse();
	sort(v.begin(),v.end());
	for(i=0;i<v.size();i++){
		ll x = v[i];
		if(k%(n/x)!=0) continue;
		cnt[x] = comb(x,x*k/n);
		for(j=2;j<x;j++){
			if(x%j==0){
				cnt[x] -= cnt[j];
				if(cnt[x]<0) cnt[x] += mod;
			}
		}
		(ans += cnt[x]) %= mod;
	}
	cout << ans << endl;
}
0