結果

問題 No.546 オンリー・ワン
ユーザー ゆにぽけゆにぽけ
提出日時 2023-10-26 08:59:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,043 bytes
コンパイル時間 1,437 ms
コンパイル使用メモリ 126,892 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 08:59:32
合計ジャッジ時間 2,246 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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