結果
| 問題 |
No.546 オンリー・ワン
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-15 04:03:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 2,000 ms |
| コード長 | 1,646 bytes |
| コンパイル時間 | 4,087 ms |
| コンパイル使用メモリ | 250,672 KB |
| 最終ジャッジ日時 | 2025-02-21 14:04:42 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 |
ソースコード
#include <bits/stdc++.h>
// clang-format off
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class S>inline bool chmax(T &a,const S &b) {return (a<b? a=b,1:0);}
template<class T,class S>inline bool chmin(T &a,const S &b) {return (a>b? a=b,1:0);}
template<class T,class S>inline T floor(T a,S b) {if(b<0)a=-a,b=-b;return a>=0?a/b:(a+1)/b-1;}
template<class T,class S>inline T ceil(T a,S b) {if(b<0)a=-a,b=-b;return a>0?(a-1)/b+1:a/b;}
constexpr int dx[8]={1,0,-1,0,1,-1,1,-1},dy[8]={0,1,0,-1,1,-1,-1,1};
using ll = long long;
// clang-format on
#ifdef LOCAL
#include <util/debug_print.hpp>
#else
#define debug(...) static_cast<void>(0)
#endif
ll gcd(ll a, ll b) {
return (b == 0) ? a : gcd(b, a % b);
}
ll INF = 2e18;
ll lcm(ll a, ll b) {
if (a / gcd(a, b) > INF / b) return INF;
return a / gcd(a, b) * b;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
ll L, H;
cin >> L >> H;
vector<ll> A(n);
rep(i, n) cin >> A[i];
auto f = [&](ll m) -> ll {
ll ans = 0;
rep(i, n) {
ll tmp = 0;
rep(bit, 1 << n) {
if (bit >> i & 1) {
ll x = 1;
rep(j, n) if (bit >> j & 1) x = lcm(x, A[j]);
if (x == INF) continue;
if (__builtin_popcount(bit) % 2) tmp += m / x;
else tmp -= m / x;
}
}
ans += tmp;
}
return ans;
};
ll ans = f(H) - f(L - 1);
cout << ans << '\n';
return 0;
}