結果
| 問題 |
No.546 オンリー・ワン
|
| コンテスト | |
| ユーザー |
zawakasu
|
| 提出日時 | 2022-09-01 04:06:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 982 bytes |
| コンパイル時間 | 1,858 ms |
| コンパイル使用メモリ | 196,576 KB |
| 最終ジャッジ日時 | 2025-02-07 00:21:59 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using i32 = int;
using i64 = long long;
const i32 sup = 2e9;
int main() {
i32 n, l, h; cin >> n >> l >> h;
vector<i32> cs(n);
for (auto& c : cs) cin >> c;
auto get = [&](i32 x) {
return h / x - (l - 1) / x;
};
auto Lcm = [&](i32 a, i32 b) -> i32 {
if (a / gcd(a, b) > sup / b) return sup;
else return lcm(a, b);
};
i32 ans = 0;
for (i32 i = 0 ; i < n ; i++) {
ans += get(cs[i]);
for (i32 bit = 1 ; bit < (1 << n) ; bit++) {
if (!(bit & (1 << i))) continue;
if (__builtin_popcount(bit) == 1) continue;
i32 mul = 1;
for (i32 j = 0 ; j < n ; j++) {
if (!(bit & (1 << j))) continue;
mul = Lcm(mul, cs[j]);
}
// cout << get(mul) << endl;
ans += (__builtin_popcount(bit) & 1 ? get(mul) : -get(mul));
}
}
cout << ans << endl;
}
zawakasu