結果

問題 No.546 オンリー・ワン
ユーザー 0w10w1
提出日時 2017-08-09 14:43:19
言語 Ruby
(3.4.1)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 399 bytes
コンパイル時間 44 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-10-12 03:54:49
合計ジャッジ時間 1,527 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, L, H = gets.split.map &:to_i
C = gets.split.map &:to_i

def solve x, c
  res = 0
  1.upto((1 << c.size) - 1) do |s|
    lcm, cnt = 1, 0
    c.size.times do |i|
      next if (s >> i & 1) == 0
      cnt += 1
      lcm = lcm * c[i] / lcm.gcd(c[i])
    end
    if (cnt & 1) == 1
      res += x / lcm * cnt
    else
      res -= x / lcm * cnt
    end
  end
  res
end

p solve(H, C) - solve(L - 1, C)
0