結果

問題 No.546 オンリー・ワン
ユーザー ゆにぽけ
提出日時 2023-10-26 08:59:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,043 bytes
コンパイル時間 1,156 ms
コンパイル使用メモリ 122,692 KB
最終ジャッジ日時 2025-02-17 13:48:20
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
#include<functional>
#include<utility>
using namespace std;
long long gcd(long long a,long long b)
{
	while(b)
	{
		a %= b;
		swap(a,b);
	}
	return a;
}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}
int N,L,H;
long long C[10];
long long f(long long x)
{
	long long res = 0;
	for(int i = 1;i < 1 << N;i++)
	{
		long long l = 1;
		for(int j = 0;j < N;j++) if(i >> j & 1) l = lcm(l,C[j]);
		int b = __builtin_popcount(i);
		long long cur = x/l*b;
		if(b & 1) res += cur;
		else res -= cur;
	}
	return res;
}
void solve()
{
	cin >> N >> L >> H;
	for(int i = 0;i < N;i++) cin >> C[i];
	cout << f(H) - f(L-1) << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while(tt--) solve();
}
0