結果

問題 No.546 オンリー・ワン
ユーザー AC2KAC2K
提出日時 2023-05-05 13:51:36
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,512 bytes
コンパイル時間 2,705 ms
コンパイル使用メモリ 247,196 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 10:08:16
合計ジャッジ時間 3,249 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#line 2 "library/src/template.hpp"
#include<bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(x) (x).begin(),(x).end()
#define popcount(x) __builtin_popcount(x)
using i128=__int128_t;
using ll = long long;
using ld = long double;
using graph = std::vector<std::vector<int>>;
using P = std::pair<int, int>;
constexpr int inf = 1e9;
constexpr ll infl = 1e18;
constexpr ld eps = 1e-6;
const long double pi = acos(-1);
constexpr uint64_t MOD = 1e9 + 7;
constexpr uint64_t MOD2 = 998244353;
constexpr int dx[] = { 1,0,-1,0 };
constexpr int dy[] = { 0,1,0,-1 };
template<class T>constexpr inline void chmax(T&x,T y){if(x<y)x=y;}
template<class T>constexpr inline void chmin(T&x,T y){if(x>y)x=y;}
#line 2 "main.cpp"
using namespace std;
int n, l, h;
int c[10];
/// iのみで割り切れるような数 
ll solve(int i) {
    vector<ll> cv;
    rep(j, n) if (j != i) cv.emplace_back(c[j]);
    ll res = 0;
    for (int msk = 0; msk < (1 << (n - 1)); ++msk) {
        bool flag = true;
        ll mul = c[i];
        rep(j, n - 1) if ((msk >> j) & 1) {
            mul = lcm(mul, cv[j]);
            if (mul >= inf) {
                flag = false;
                break;
            }
        }
        if (!flag) continue;

        ll hi = h / mul, lo = (l - 1) / mul;

        res += (~popcount(msk) & 1 ? 1 : -1) * (hi - lo);
    }
    return res;
}
int main() {
    cin >> n >> l >> h;
    rep(i, n) cin >> c[i];
    ll ans = 0;
    rep(i, n) { ans += solve(i); }
    cout << ans << '\n';
}
0