結果

問題 No.546 オンリー・ワン
ユーザー uenokuuenoku
提出日時 2017-08-24 02:56:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 1,455 ms
コンパイル使用メモリ 165,004 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 13:39:36
合計ジャッジ時間 2,060 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
lli lcm(lli l, lli r)
{
    return l / __gcd(l, r) * r;
}
lli memo_h[1 << 20], memo_l[1 << 20];
int main()
{
    lli c[20], l, h;
    int n;
    cin >> n >> l >> h;
    lli sum_l = 0, sum_h = 0;
    rep(i, n) cin >> c[i];
    for (int i = 0; i < (1 << n); i++) {
        lli LCM = 1;
        rep(j, n)
        {
            if ((i >> j) & 1) {
                LCM = lcm(LCM, c[j]);
            }
        }
        lli count = __builtin_popcount(i);
        sum_h += (count & 1 ? 1 : -1) * count * (h / LCM);
        sum_l += (count & 1 ? 1 : -1) * count * ((l - 1) / LCM);

        //memo_h[i] = h / LCM;
        //memo_l[i] = (l - 1) / LCM;
    }
    cout << sum_h - sum_l << endl;
}
0