結果

問題 No.890 移調の限られた旋法
ユーザー HIR180HIR180
提出日時 2019-09-21 00:01:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 1,353 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 153,200 KB
実行使用メモリ 19,300 KB
最終ジャッジ日時 2023-10-13 08:44:32
合計ジャッジ時間 8,188 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
18,996 KB
testcase_01 AC 142 ms
18,972 KB
testcase_02 AC 142 ms
18,996 KB
testcase_03 AC 142 ms
18,976 KB
testcase_04 AC 142 ms
19,092 KB
testcase_05 AC 142 ms
18,980 KB
testcase_06 AC 142 ms
19,076 KB
testcase_07 AC 143 ms
19,020 KB
testcase_08 AC 142 ms
19,008 KB
testcase_09 AC 142 ms
18,972 KB
testcase_10 AC 142 ms
18,972 KB
testcase_11 AC 143 ms
18,972 KB
testcase_12 AC 143 ms
18,980 KB
testcase_13 AC 142 ms
19,028 KB
testcase_14 AC 142 ms
18,976 KB
testcase_15 AC 142 ms
19,100 KB
testcase_16 AC 142 ms
18,996 KB
testcase_17 AC 142 ms
18,976 KB
testcase_18 AC 142 ms
18,988 KB
testcase_19 AC 142 ms
19,040 KB
testcase_20 AC 142 ms
19,024 KB
testcase_21 AC 142 ms
18,980 KB
testcase_22 AC 142 ms
19,024 KB
testcase_23 AC 142 ms
18,980 KB
testcase_24 AC 142 ms
19,300 KB
testcase_25 AC 142 ms
19,088 KB
testcase_26 AC 142 ms
18,976 KB
testcase_27 AC 142 ms
18,972 KB
testcase_28 AC 142 ms
18,976 KB
testcase_29 AC 142 ms
19,048 KB
testcase_30 AC 143 ms
19,180 KB
testcase_31 AC 142 ms
19,176 KB
testcase_32 AC 142 ms
19,024 KB
testcase_33 AC 142 ms
19,028 KB
testcase_34 AC 141 ms
18,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,k;
vector<int>vi;
vector<ll>ans;
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[1000005],R[1000005];
void make(){
	F[0] = 1;
	for(int i=1;i<1000005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<1000005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
int main(){ make();
	cin >> n >> k;
	for(int i=1;i*i<=n;i++) if(n%i==0){
		vi.pb(i);
		if(i*i < n) vi.pb(n/i);
	}
	SORT(vi);
	rep(i,vi.size()){
		int x = n / vi[i];
		if(k%x != 0){
			ans.pb(0);
		}
		else{
			ll cur = C(vi[i],k/x);
			rep(j,i){
				if(vi[i]%vi[j] == 0) cur -= ans[j];
			}
			ans.pb(cur);
		}
	}
	ll ret = 0; rep(i,ans.size()-1) ret+=ans[i];
	cout<<(ret%mod+mod)%mod<<endl;
}
0