結果

問題 No.546 オンリー・ワン
ユーザー ゆにぽけゆにぽけ
提出日時 2023-10-26 08:41:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,009 bytes
コンパイル時間 1,389 ms
コンパイル使用メモリ 127,104 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-26 08:41:02
合計ジャッジ時間 2,260 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
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];
void solve()
{
	cin >> N >> L >> H;
	for(int i = 0;i < N;i++) cin >> C[i];
	long long ans = 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 = (H/l - (L+l-1)/l + 1)*b;
		if(b & 1) ans += cur;
		else ans -= cur;
	}
	cout << ans << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while(tt--) solve();
}
0