結果

問題 No.546 オンリー・ワン
ユーザー hashiryohashiryo
提出日時 2020-06-14 19:26:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 166,356 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-27 17:25:43
合計ジャッジ時間 2,099 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

long long lcm(long long x, long long y) { return x * y / __gcd(x, y); }

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, L, H;
  cin >> N >> L >> H;
  int C[N];
  for (int i = 0; i < N; i++) cin >> C[i];
  long long ans = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    int cnt = __builtin_popcount(bit);
    long long mul = 1;
    for (int i = 0; i < N; i++)
      if ((bit >> i) & 1) mul = lcm(mul, C[i]);
    long long tmp = H / mul - (L - 1) / mul;
    if (cnt & 1)
      ans += cnt * tmp;
    else
      ans -= cnt * tmp;
  }
  cout << ans << endl;
  return 0;
}
0