結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
28,460 KB
testcase_01 AC 61 ms
28,452 KB
testcase_02 AC 61 ms
28,452 KB
testcase_03 AC 65 ms
28,460 KB
testcase_04 AC 62 ms
28,436 KB
testcase_05 AC 61 ms
28,468 KB
testcase_06 WA -
testcase_07 AC 64 ms
28,676 KB
testcase_08 AC 63 ms
28,600 KB
testcase_09 AC 64 ms
28,516 KB
testcase_10 AC 63 ms
28,604 KB
testcase_11 AC 62 ms
28,512 KB
testcase_12 AC 63 ms
28,480 KB
testcase_13 WA -
testcase_14 AC 64 ms
28,552 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 60 ms
28,436 KB
testcase_21 AC 62 ms
28,452 KB
testcase_22 AC 60 ms
30,516 KB
testcase_23 AC 61 ms
28,532 KB
testcase_24 AC 61 ms
30,508 KB
testcase_25 AC 60 ms
28,464 KB
testcase_26 AC 63 ms
30,540 KB
testcase_27 AC 60 ms
28,468 KB
testcase_28 AC 61 ms
28,468 KB
testcase_29 AC 61 ms
28,436 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
	}
	cout << ans << endl;
}
			
0