結果

問題 No.546 オンリー・ワン
ユーザー T1610T1610
提出日時 2019-03-23 01:55:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,217 bytes
コンパイル時間 2,281 ms
コンパイル使用メモリ 169,680 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-19 15:10:25
合計ジャッジ時間 2,861 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

ll calc(ll N, ll x) {
    return N / x;
}

ll calc(ll l, ll r, ll x) {
    if(l == 1) return calc(r, x);
    else return calc(r, x) - calc(l-1, x);
}

ll lcm(ll a, ll b) {
    return a / __gcd(a, b) * b;
}

int main(){
    ll N, L, H;
    cin >> N >> L >> H;
    vl c(N);
    rep(i, N) cin >> c[i];
    ll ans = 0LL;
    REP(mask, 1, 1<<N) {
        ll x = 1LL;
        int cnt = __builtin_popcount(mask);
        rep(i, N) if(mask & (1<<i)) x = lcm(x, c[i]);
        if(cnt&1) ans += calc(L, H, x) * cnt;
        else ans -= calc(L, H, x) * cnt;
        // cout << bitset<6>(mask) << " " << x << " " << calc(L, H, x) << endl;
    }
    cout << ans << endl;
    return 0;
}
0