結果

問題 No.546 オンリー・ワン
ユーザー furafura
提出日時 2020-07-25 03:01:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 869 bytes
コンパイル時間 2,118 ms
コンパイル使用メモリ 201,172 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 11:02:35
合計ジャッジ時間 2,789 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

inline int popcount(int x){
	x=((x>>1)&0x55555555)+(x&0x55555555);
	x=((x>>2)&0x33333333)+(x&0x33333333);
	x=((x>>4)+x)&0x0f0f0f0f;
	x+=(x>>8);
	x+=(x>>16);
	return x&0x3f;
}

int main(){
	int choose[11][11]={};
	rep(i,11) choose[i][0]=1;
	rep(i,10) rep(j,i+1) choose[i+1][j+1]=choose[i][j]+choose[i][j+1];

	int n;
	lint l,r; scanf("%d%lld%lld",&n,&l,&r);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	int coef[11];
	for(int i=2;i<=n;i++){
		coef[i]=i;
		for(int j=2;j<i;j++) coef[i]-=choose[i][j]*coef[j];
	}

	lint ans=0;
	rep(S,1<<n) if(S!=0) {
		lint L=1;
		rep(i,n) if(S>>i&1) L=min(lcm(L,a[i]),r+1);
		int pc=popcount(S);
		if(pc==1){
			ans+=r/L-(l-1)/L;
		}
		else{
			ans-=coef[pc]*(r/L-(l-1)/L);
		}
	}
	printf("%lld\n",ans);

	return 0;
}
0