結果
| 問題 | No.546 オンリー・ワン | 
| コンテスト | |
| ユーザー |  0x19f | 
| 提出日時 | 2017-07-15 20:31:23 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,860 bytes | 
| コンパイル時間 | 617 ms | 
| コンパイル使用メモリ | 74,980 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-08 02:40:14 | 
| 合計ジャッジ時間 | 1,100 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;
typedef long long ll;
int N;
ll L, H, C[10];
template<typename FI>
void parted_rotate(FI first1, FI last1, FI first2, FI last2) {
  if(first1 == last1 || first2 == last2) return;
  FI next = first2;
  while(first1 != next) {
    std::iter_swap(first1++, next++);
    if(first1 == last1) first1 = first2;
    if(next == last2) {
      next = first2;
    } else if(first1 == first2) {
      first2 = next;
    }
  }
}
template<typename BI>
bool next_combination_imp(BI first1, BI last1, BI first2, BI last2) {
  if(first1 == last1 || first2 == last2) return false;
  auto target = last1; --target;
  auto last_elem = last2; --last_elem;
  while(target != first1 && !(*target < *last_elem)) --target;
  if(target == first1 && !(*target < *last_elem)) {
    parted_rotate(first1, last1, first2, last2);
    return false;
  }
  auto next = first2;
  while(!(*target < *next)) ++next;
  std::iter_swap(target++, next++);
  parted_rotate(target, last1, next, last2);
  return true;
}
template<typename BI>
inline bool next_combination(BI first, BI mid, BI last) {
  return next_combination_imp(first, mid, mid, last);
}
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}
int main(void) {
  cin >> N >> L >> H;
  REP(i, 0, N) cin >> C[i];
  ll fact[11];
  fact[0] = 1;
  REP(i, 0, 10) fact[i + 1] = fact[i] * (i + 1);
  ll ans = 0;
  REP(i, 1, N + 1) {
    ll a[20];
    REP(i, 0, N) a[i] = i;
    ll cnt = 0;
    do {
      ll p = 1;
      REP(j, 0, i) p = lcm(p, C[a[j]]);
      cnt += H / p - (L - 1) / p;
    } while(next_combination(a, a + i, a + N));
    ans += (i % 2 == 0 ? -1 : 1) * i * cnt;
  }
  cout << ans << endl;
}
            
            
            
        