結果

問題 No.546 オンリー・ワン
ユーザー kappybarkappybar
提出日時 2020-06-07 19:30:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 1,201 ms
コンパイル使用メモリ 166,928 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 12:59:48
合計ジャッジ時間 1,966 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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