結果

問題 No.546 オンリー・ワン
ユーザー WA_TLEWA_TLE
提出日時 2017-07-14 22:59:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,322 bytes
コンパイル時間 1,271 ms
コンパイル使用メモリ 124,088 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 20:29:24
合計ジャッジ時間 1,721 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<random>
#include<unordered_set>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const llint mod=1000000007;
const llint big=1e9+10;
const long double pai=3.141592653589793238462643383279;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(b==0){return a;}return gcd(b,a%b);}//a>b
llint lcm(llint a,llint b){return (a/gcd(max(a,b),min(a,b)))*b;}
int n;
vector<int>c;
int solve(llint in){
	llint ans=0;
	for(int bit=0;bit<(1<<n);bit++){
		llint co=0,alc=1;
		for(int i=0;i<n;i++){
			if((bit&(1<<i))==0){continue;}
			co++;
			alc=lcm(alc,c[i]);
			if(alc>in){co=0;break;}//だめだ
		}
		if(co%2==1){ans+=co*(in/alc);}
		else{ans-=co*(in/alc);}
	}
	return ans;
}
int main(void){
	llint l,h;cin>>n>>l>>h;
	c.res(n);
	for(int i=0;i<n;i++){cin>>c[i];}
	cout<<solve(h)-solve(l-1)<<endl;
	return 0;
}
0