結果

問題 No.1895 Mod 2
ユーザー simansiman
提出日時 2022-06-01 03:30:05
言語 Ruby
(3.3.0)
結果
AC  
実行時間 377 ms / 2,000 ms
コード長 485 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 16,208 KB
最終ジャッジ日時 2023-10-21 00:46:08
合計ジャッジ時間 5,790 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
16,092 KB
testcase_01 AC 369 ms
16,200 KB
testcase_02 AC 369 ms
16,200 KB
testcase_03 AC 363 ms
16,200 KB
testcase_04 AC 365 ms
16,200 KB
testcase_05 AC 377 ms
16,200 KB
testcase_06 AC 374 ms
16,200 KB
testcase_07 AC 373 ms
16,200 KB
testcase_08 AC 366 ms
16,200 KB
testcase_09 AC 369 ms
16,200 KB
testcase_10 AC 368 ms
16,200 KB
testcase_11 AC 372 ms
16,208 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

T = gets.to_i

def f(x)
  ok = 0
  ng = 10 ** 15

  while (ok - ng).abs >= 2
    v = (ok + ng) / 2

    if v * v <= x
      ok = v
    else
      ng = v
    end
  end

  ok
end

def g(x)
  ok = 0
  ng = 10 ** 15

  while (ok - ng).abs >= 2
    v = (ok + ng) / 2

    if 2 * v * v <= x
      ok = v
    else
      ng = v
    end
  end

  ok
end

T.times do
  l, r = gets.split.map(&:to_i)

  v1 = f(l - 1)
  v2 = f(r)
  v3 = g(l - 1)
  v4 = g(r)

  puts ((v2 + v4) - (v1 + v3)) % 2
end
0