結果

問題 No.546 オンリー・ワン
ユーザー face4face4
提出日時 2019-02-12 14:17:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 671 bytes
コンパイル時間 448 ms
コンパイル使用メモリ 63,980 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 10:53:52
合計ジャッジ時間 1,288 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// 包除原理?
#include<iostream>
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b){
    return b == 0 ? a : gcd(b, a%b);
}

int main(){
    int n, l, h;
    cin >> n >> l >> h;
    int c[n];
    for(int i = 0; i < n; i++)  cin >> c[i];
    ll ret = 0;
    for(int s = 1; s < 1<<n; s++){
        int pop = 0; ll accum = 1;
        for(int i = 0; i < n; i++){
            if(accum > h)   break;
            if((s>>i)&1)    pop++, accum = accum * c[i] / gcd(accum, c[i]);
        }
        if(accum > h)   continue;
        ll x = (l+accum-1)/accum, y = h/accum;
        ret += (2*(pop%2)-1) * (y-x+1) * pop;
    }
    cout << ret << endl;
    return 0;
}
0