結果

問題 No.546 オンリー・ワン
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-07-15 00:45:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,224 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 168,296 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-07-29 15:07:29
合計ジャッジ時間 2,224 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
typedef long long ll;
ll countMultiple(ll L, ll R, ll div) {
    if (R % div == 0) {
        if (L % div == 0) return R / div - L / div + 1;
        else return R / div - L / div;
    } else {
        if (L % div == 0) return R / div - L / div + 1;
        else return R / div - L / div;
    }
}
typedef long long ll; typedef long double ld;
#define INF 1LL<<60
ld lginf = -1;
ll mul(ll a, ll b) {
    if (lginf < 0) lginf = log10l(INF); ld aa = log10l(a), bb = log10l(b);
    if (lginf <= aa + bb) return INF; return a * b;
}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
ll lcm(ll a, ll b) { if (a == INF || b == INF) return INF; return mul(a / gcd(a, b), b); }
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/


int N;
ll L, H;
ll C[11];
ll cn[11];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> L >> H;
    rep(i, 0, N) cin >> C[i];

    ll ans = 0;
    rep(i, 0, N) {
        vector<ll> CC;
        ll d = 0;
        rep(j, 0, N) if (i != j) CC.push_back(C[j]);
        rep(mask, 0, 1<<(N - 1)) {
            ll lc = C[i];
            int cnt = 0;
            rep(j, 0, N - 1) if (mask & (1 << j)) lc = lcm(lc, CC[j]), cnt++;

            ll c = countMultiple(L, H, lc);
            if (cnt % 2 == 0) d += c;
            else d -= c;
        }
        ans += d;
    }
    cout << ans << endl;
}
0