結果
問題 | No.546 オンリー・ワン |
ユーザー | ldsyb |
提出日時 | 2017-12-25 06:41:24 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 729 bytes |
コンパイル時間 | 1,511 ms |
コンパイル使用メモリ | 164,744 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-08-22 18:37:33 |
合計ジャッジ時間 | 2,189 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { while (b) { T tmp = b; b = a % b; a = tmp; } return a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } int main() { int64_t n, a, b; cin >> n >> a >> b; int64_t c[n]; for (auto &i : c) { cin >> i; } auto f = [&](int64_t x) { int64_t ans = 0; for (int i = 1; i < (1 << n); i++) { int64_t l = 1, count = 0; for (int j = 0; j < n; j++) { if ((i >> j) & 1) { l = lcm(l, c[j]); count++; if (x < l) { goto next; } } } ans += count * max(int64_t(0), x / l) * pow(-1, count + 1); next:; } return ans; }; cout << f(b) - f(a - 1) << endl; return 0; }