結果
| 問題 |
No.546 オンリー・ワン
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-23 19:18:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,092 bytes |
| コンパイル時間 | 618 ms |
| コンパイル使用メモリ | 59,736 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-17 16:33:01 |
| 合計ジャッジ時間 | 1,200 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 10;
typedef long long int ll;
ll dp[1 << N] = {}, n, l, h, val[N] = {};
int nmb(long bits)
{
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}
ll gcd(ll a, ll b) {
if (a == 0)return b;
if (b == 0)return a;
ll a2 = max(a, b), b2 = min(a, b);
return gcd(b2, a2%b2);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b)*b;
}
ll ans = 0;
int main() {
cin >> n >> l >> h;
for (int i = 0; i < n; i++) cin >> val[i];
for (int s = 0; s < (1 << n); s++) {
ll cd = 1;
for (int i = 0; i < n; i++) {
if ((s >> i) & 1)cd = lcm(cd, val[i]);
if (cd > h)break;
}
dp[s] = h / cd - (l - 1) / cd;
}
for (int s = 0; s < (1 << n); s++) {
int cnmb = nmb(s);
if (cnmb % 2 == 0)ans -= cnmb * dp[s];
else ans += cnmb * dp[s];
}
cout << ans << endl;
return 0;
}