結果

問題 No.890 移調の限られた旋法
ユーザー pockynypockyny
提出日時 2019-09-20 22:40:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,061 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 81,328 KB
実行使用メモリ 30,908 KB
最終ジャッジ日時 2023-10-12 20:19:28
合計ジャッジ時間 4,270 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
28,496 KB
testcase_01 AC 58 ms
28,580 KB
testcase_02 AC 62 ms
28,468 KB
testcase_03 AC 63 ms
28,608 KB
testcase_04 AC 64 ms
28,664 KB
testcase_05 AC 64 ms
28,480 KB
testcase_06 WA -
testcase_07 AC 59 ms
28,432 KB
testcase_08 AC 60 ms
28,608 KB
testcase_09 AC 60 ms
28,496 KB
testcase_10 AC 59 ms
28,480 KB
testcase_11 AC 59 ms
28,440 KB
testcase_12 AC 59 ms
28,468 KB
testcase_13 AC 60 ms
30,760 KB
testcase_14 AC 61 ms
28,444 KB
testcase_15 AC 60 ms
30,564 KB
testcase_16 AC 60 ms
30,684 KB
testcase_17 AC 59 ms
30,592 KB
testcase_18 AC 59 ms
30,600 KB
testcase_19 AC 59 ms
30,612 KB
testcase_20 AC 59 ms
28,436 KB
testcase_21 AC 58 ms
28,452 KB
testcase_22 AC 59 ms
30,724 KB
testcase_23 AC 58 ms
28,436 KB
testcase_24 AC 60 ms
30,484 KB
testcase_25 AC 60 ms
28,440 KB
testcase_26 AC 63 ms
30,492 KB
testcase_27 AC 59 ms
28,612 KB
testcase_28 AC 58 ms
28,552 KB
testcase_29 AC 59 ms
28,468 KB
testcase_30 AC 61 ms
30,756 KB
testcase_31 AC 59 ms
28,768 KB
testcase_32 AC 60 ms
30,716 KB
testcase_33 WA -
testcase_34 AC 58 ms
30,584 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*j<=x;j++){
			if(x%j==0){
				cnt[x] -= cnt[j];
				if(cnt[x]<0) cnt[x] += mod;
				if(j*j!=x){
					cnt[x] -= cnt[x/j];
					if(cnt[x]<0) cnt[x] += mod;
				}
			}
		}
		(ans += cnt[x]) %= mod;
	}
	cout << ans << endl;
}
			
0