結果

問題 No.546 オンリー・ワン
ユーザー kappybarkappybar
提出日時 2020-06-07 19:30:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 1,876 ms
コンパイル使用メモリ 169,052 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 20:37:20
合計ジャッジ時間 2,448 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr ll MOD = 1e12;
constexpr double PI = 3.14159265358979323846;

ll gcd(ll i,ll j){
    if(j == 0) return i;
    return gcd(j,i%j);
}

ll lcm(ll i,ll j){
    return i / gcd(i,j) * j;
}


ll count(ll p,ll l,ll h){
    ll a = (l+p-1)/p;
    ll b = h/p ;
    return max(b-a+1,0LL);
}

int main(){
    int n;
    ll l,h;
    cin >> n >> l >> h;
    vector<ll> c(n);
    rep(i,n) cin >> c[i];
    ll ans = 0;
    for(int bit=0;bit<(1<<n);bit++){
        bool overflow = false;
        int cnt = 0;
        ll res = 1;
        for(int i=0;i<n;i++){
            if(bit>>i & 1){
                ll p = lcm(res,c[i]);
                if(p > h){
                    overflow = true;
                    break;
                }else{
                    res = p;
                    ++ cnt;
                }
            }
        }
        if(!overflow) ans += cnt * (cnt%2==0?-1:1) * count(res,l,h);
    }
    cout << ans << endl;
    return 0;
}
0