結果
| 問題 | No.546 オンリー・ワン | 
| コンテスト | |
| ユーザー |  tsutaj | 
| 提出日時 | 2018-10-12 16:24:59 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 1,075 bytes | 
| コンパイル時間 | 858 ms | 
| コンパイル使用メモリ | 71,708 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-12 17:47:38 | 
| 合計ジャッジ時間 | 1,020 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
using ll = long long int;
ll N, L, H;
ll gcd(ll A, ll B) {
    return B ? gcd(B, A%B) : A;
}
ll lcm(ll A, ll B) {
    return A / gcd(A, B) * B;
}
ll solve(vector<ll> vec, ll val, ll M) {
    ll res = M / val;
    int sz = vec.size();
    for(int bit=1; bit<(1<<sz); bit++) {
        ll mul = val;
        for(int i=0; i<sz; i++) {
            if(bit >> i & 1) mul = lcm(mul, vec[i]);
            if(mul > M) goto OutOfLoop;
        }
        if(__builtin_popcount(bit) % 2) res -= M / mul;
        else                            res += M / mul;
        OutOfLoop:;
    }
    return res;
}
ll solve(vector<ll> vec, ll val) {
    return solve(vec, val, H) - solve(vec, val, L-1);
}
int main() {
    cin >> N >> L >> H;
    vector<ll> C(N);
    for(int i=0; i<N; i++) {
        cin >> C[i];
    }
    ll ans = 0;
    for(int i=0; i<N; i++) {
        vector<ll> D = C;
        ll val = D[i]; D.erase(D.begin() + i);
        ans += solve(D, val);
    }
    cout << ans << endl;
    return 0;
}
            
            
            
        