結果

問題 No.546 オンリー・ワン
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-07-14 23:13:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,951 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 168,900 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 20:31:47
合計ジャッジ時間 2,045 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 3 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 7 ms
5,376 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;
    }
}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
ll lcm(ll a, ll b) { return 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