結果

問題 No.546 オンリー・ワン
ユーザー zawakasuzawakasu
提出日時 2022-09-01 04:06:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 982 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 197,076 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 08:55:16
合計ジャッジ時間 2,673 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0