結果
問題 | No.546 オンリー・ワン |
ユーザー | mamekin |
提出日時 | 2017-07-14 23:04:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,463 bytes |
コンパイル時間 | 1,044 ms |
コンパイル使用メモリ | 103,172 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-07 23:26:38 |
合計ジャッジ時間 | 1,689 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
#define _USE_MATH_DEFINES#include <cstdio>#include <iostream>#include <sstream>#include <fstream>#include <iomanip>#include <algorithm>#include <cmath>#include <complex>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <set>#include <map>#include <bitset>#include <numeric>#include <limits>#include <climits>#include <cfloat>#include <functional>#include <iterator>using namespace std;long long gcd(long long a, long long b){while(b != 0){long long tmp = a % b;a = b;b = tmp;}return a;}long long lcm(long long a, long long b){return a / gcd(a, b) * b;}long long solve(const vector<int>& c, int limit){int n = c.size();long long ans = 0;for(int i=1; i<(1<<n); ++i){bitset<32> bs(i);long long x = 1;for(int j=0; j<n; ++j){if(bs[j])x = lcm(x, c[j]);if(x > limit){x = -1;break;}}if(x != -1){int m = bs.count();if(m % 2 == 1)ans += limit / x * m;elseans -= limit / x * m;}}return ans;}int main(){int n, l, h;cin >> n >> l >> h;vector<int> c(n);for(int i=0; i<n; ++i)cin >> c[i];long long ans = solve(c, h) - solve(c, l-1);cout << ans << endl;return 0;}