結果

問題 No.546 オンリー・ワン
コンテスト
ユーザー RiRinbaru
提出日時 2026-06-02 07:50:28
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,786 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,921 ms
コンパイル使用メモリ 376,524 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-02 07:50:39
合計ジャッジ時間 8,330 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define rep(i, p, n) for (ll i = p; i < (ll)(n); i++)
#define rep2(i, p, n) for (ll i = p; i >= (ll)(n); i--)
using namespace std;
using ll = long long;
using ld = long double;
const double pi = 3.141592653589793;
const long long inf = 2 * 1e9;
const long long linf = 4 * 1e18;
const ll mod1 = 1000000007;
const ll mod2 = 998244353;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;

// atcoder
#include <atcoder/all>
using namespace atcoder;
using mint1 = modint1000000007;
using mint2 = modint998244353;

vector<pair<ll, ll>> base = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

void solve()
{
    ll N, L, H;
    cin >> N >> L >> H;
    vector<ll> C(N);
    rep(i, 0, N)
    {
        cin >> C.at(i);
    }
    ll ans = 0;
    rep(i, 1, (1 << N))
    {
        ll G = 1, co = 0;
        bool ch = true;
        rep(j, 0, N)
        {
            if (i & (1 << j) && G <= 1e9)
            {
                G = lcm(G, C.at(j));
                co++;
            }
            if (G > 1e9)
            {
                ch = false;
            }
        }
        if (ch)
        {
            if (co%2==1)
            {
                ans += co * (H / G - (L - 1) / G);
            }
            else
            {
                ans -= co * (H / G - (L - 1) / G);
            }
        }
    }
    cout << ans << endl;
}

int main()
{

    //////////////////
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //////////////////

    solve();
}
0