結果

問題 No.890 移調の限られた旋法
ユーザー okok
提出日時 2019-09-20 22:24:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,955 bytes
コンパイル時間 755 ms
コンパイル使用メモリ 83,060 KB
実行使用メモリ 27,140 KB
最終ジャッジ日時 2023-10-12 19:51:48
合計ジャッジ時間 2,776 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
19,728 KB
testcase_01 AC 17 ms
19,732 KB
testcase_02 AC 16 ms
19,832 KB
testcase_03 AC 17 ms
19,760 KB
testcase_04 AC 17 ms
19,732 KB
testcase_05 WA -
testcase_06 AC 16 ms
19,932 KB
testcase_07 AC 16 ms
19,736 KB
testcase_08 AC 16 ms
19,852 KB
testcase_09 AC 17 ms
19,732 KB
testcase_10 AC 16 ms
19,768 KB
testcase_11 AC 16 ms
19,736 KB
testcase_12 AC 16 ms
19,944 KB
testcase_13 AC 21 ms
26,828 KB
testcase_14 AC 21 ms
26,804 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 19 ms
24,104 KB
testcase_20 AC 18 ms
21,816 KB
testcase_21 AC 17 ms
19,756 KB
testcase_22 AC 20 ms
25,956 KB
testcase_23 AC 20 ms
26,312 KB
testcase_24 AC 19 ms
24,036 KB
testcase_25 AC 17 ms
21,864 KB
testcase_26 AC 21 ms
26,628 KB
testcase_27 WA -
testcase_28 AC 20 ms
25,996 KB
testcase_29 AC 18 ms
23,928 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 20 ms
25,880 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX_VAL (int)(1e6 + 100)

long long fac[MAX_VAL], mmi[MAX_VAL];

void factorial_mod(){
	 fac[0]=fac[1]=1;
	for(long long i = 2; i < MAX_VAL; fac[i]%=MOD,i++)
		fac[i] = fac[i-1]*(i%MOD);
}

long long power_mod(long long x, long long n){
	long long ans = 1;
	for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
		if(n&1)ans*=x;
	return ans%MOD;
}

void exgcd(int a, int b, int &x, int &y){
	if(b == 0){
		x = 1;
		y = 0;
		return ;
	}
	exgcd(b,a%b,y,x);
	y -= a/b * x;
}

void modular_multiplicatibe_inverse(){
	int x, y;  
	exgcd(fac[MAX_VAL-1],MOD,x,y);
	mmi[MAX_VAL-1] = x; 
	for(long long i = MAX_VAL-2; i >= 0; mmi[i]%=MOD,i--)
		mmi[i] = mmi[i+1]*((i+1)%MOD);
}

long long combination(long long n, long long r){
	return n < r ? 0 :fac[n]*(mmi[r]*mmi[n-r]%MOD)%MOD;
}


signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	const int MAX = 1100000;
	int N, K;
	int ans = 0;
	static int pn[MAX] = {};
	vector<int> hoge;
	
	cin>>N>>K;
	
	if(N == 1 && K == 1){
		cout<<1<<endl;
		return 0;
	}
	
	factorial_mod();
	modular_multiplicatibe_inverse();
	
	for(int i = 2; i <= N; i++){
		if(pn[i] == false){
			for(int j = i * i; j <= N; j++){
				pn[j] = true;
			}
			if(N%i == 0)hoge.push_back(i);
		}
	}
	
	int x = hoge.size();
	
	for(int i = 1; i < 1<<x; i++){
		int con = 0;
		int pro = 1;
		for(int k = 0; k < x; k++){
			if((i>>k)&1){
				con++;
				pro *= hoge[k];
			}
		}
		
		if(con%2){
			if(K%pro == 0) ans += combination(N/pro, K/pro);
			ans %= MOD;
		} else {
			if(K%pro == 0) ans -= combination(N/pro, K/pro);
			ans += MOD;
			ans %= MOD;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0