結果
問題 | No.546 オンリー・ワン |
ユーザー |
![]() |
提出日時 | 2020-06-28 21:08:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,147 bytes |
コンパイル時間 | 1,921 ms |
コンパイル使用メモリ | 197,744 KB |
最終ジャッジ日時 | 2025-01-11 13:27:30 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
#include <bits/stdc++.h>#define M_PI 3.14159265358979323846 // piusing namespace std;typedef long long ll;typedef unsigned long long ull;typedef vector<ll> VI;typedef pair<ll, ll> P;typedef tuple<ll, ll, ll> t3;typedef tuple<ll, ll, ll, ll> t4;typedef tuple<ll, ll, ll, ll, ll> t5;#define rep(a,n) for(ll a = 0;a < n;a++)#define repi(a,b,n) for(ll a = b;a < n;a++)using namespace std;static const ll INF = 1e15;const ll mod = 1000000007;ll mpow(ll x, ll n) {ll ans = 1; x %= mod;while (n != 0) {if (n & 1) ans = ans * x % mod;x = x * x % mod;n = n >> 1;}return ans;}ll inv_mod(ll a) { return mpow(a, mod - 2); }class Factorial {private:vector<ll> fac;vector<ll> ifac;public:Factorial(ll N) {fac.push_back(1);for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod);ifac.resize(N + 1);ifac[N] = inv_mod(fac[N]);for (int i = 0; i < N; i++) ifac[N - 1 - i] = (ifac[N - i] * (N - i)) % mod;}ll fact(ll a) { return fac[a]; }ll ifact(ll a) { return ifac[a]; }ll cmb(ll a, ll b) {if (a == 0 && b == 0) return 1;if (a < b || a < 0 || b < 0) return 0;ll tmp = ifact(a - b) * ifact(b) % mod;return tmp * fac[a] % mod;}ll per(ll a, ll b) {if (a == 0 && b == 0) return 1;if (a < b || a < 0 || b < 0) return 0;return fac[a] * ifac[a - b] % mod;}};ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return abs(a); }ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }int main() {ll n, l, h;cin >> n >> l >> h;vector<ll> cs(n);rep(i, n) cin >> cs[i];vector<ll> state(1 << n, 0);rep(i, 1LL << n) {ll x = 1;rep(j, n) {if (i & (1LL << j)) {x = lcm(x, cs[j]);if (x > h) break;}}if (x > h) continue;ll div = h / x - (l - 1) / x;state[i] = div;}//1の場合//1のみ +//1と2, 1 と3, ..., 1とn-1 -//1と2と3, 1 と3 と4, ..., +//を1,2,3と繰り返すため、__builtin_popcountllの数だけ加算される。ll sum = 0;rep(i, 1LL << n) {auto p = __builtin_popcountll(i);ll s = p % 2 == 1 ? 1 : -1;sum += s * state[i] * p;}cout << sum << endl;return 0;}