結果

問題 No.546 オンリー・ワン
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2021-01-19 13:44:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,514 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 79,164 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 11:06:32
合計ジャッジ時間 1,660 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
#include<numeric>
#include<array>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = size_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
template<typename T>
using vec = vector<T>;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define len(hoge) (i64)((hoge).size())
using P = pair<i64,i64>;
void solve(){
}
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 n,l,h;
    cin >> n >> l >> h;
    l--;
    i64 H = 0,L = 0;
    array<i64,10> a;
    rep(i,n)cin >> a[i];
    for(i32 bit = 1; bit < (1 << n); bit++){
        i64 mul = 1;
        rep(i,n){
            if(bit & (1 << i)){
                mul = lcm(mul,a[i]);
            }
        }
        i64 cnt = __builtin_popcount(bit);
        if(cnt % 2)H += h / mul * cnt;
        else H -= h / mul * cnt;
    }
    for(i32 bit = 1; bit < (1 << n); bit++){
        i64 mul = 1;
        rep(i,n){
            if(bit & (1 << i)){
                mul = lcm(mul,a[i]);
            }
        }
        i64 cnt = __builtin_popcount(bit);
        if(cnt % 2)L += l / mul * cnt;
        else L -= l / mul * cnt;
    }
    cout <<  H - L << endl;
}
0