結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー toshiro_yanagi
提出日時 2022-07-16 19:09:01
言語 Nim
(2.2.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 629 bytes
コンパイル時間 3,906 ms
コンパイル使用メモリ 63,872 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-28 19:08:45
合計ジャッジ時間 5,132 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils


proc nextString(): string =
  while not stdin.endOfFile:
    let c = stdin.readChar
    if c == ' ' or c == '\n': break
    elif c != '\r': result.add(c)


proc gcd(x, y: int): int =
  var a = x
  var b = y
  if a < b: swap(a, b)
  while b > 0:
    let m = a mod b
    a = b
    b = m
  return a


proc lcm(x, y: int): int =
  x * y div gcd(x, y)


proc main(): void =
  let
    n, a, b, c = parseInt(nextString())
  var
    ans = 0

  for t in [a, b, c]: ans += n div t

  for t in [lcm(a, b), lcm(b, c), lcm(c, a)]:
    ans -= n div t

  ans += n div lcm(lcm(a, b), c)

  echo ans


when isMainModule: main()
0