結果

問題 No.1593 Perfect Distance
ユーザー simansiman
提出日時 2021-07-13 14:52:46
言語 Ruby
(3.3.0)
結果
AC  
実行時間 663 ms / 2,000 ms
コード長 345 bytes
コンパイル時間 481 ms
コンパイル使用メモリ 11,368 KB
実行使用メモリ 15,220 KB
最終ジャッジ日時 2023-09-15 09:28:35
合計ジャッジ時間 5,382 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,060 KB
testcase_01 AC 81 ms
15,176 KB
testcase_02 AC 82 ms
15,056 KB
testcase_03 AC 79 ms
15,136 KB
testcase_04 AC 79 ms
15,148 KB
testcase_05 AC 80 ms
15,124 KB
testcase_06 AC 80 ms
15,204 KB
testcase_07 AC 80 ms
15,184 KB
testcase_08 AC 81 ms
15,104 KB
testcase_09 AC 99 ms
15,220 KB
testcase_10 AC 149 ms
15,124 KB
testcase_11 AC 192 ms
15,148 KB
testcase_12 AC 280 ms
15,068 KB
testcase_13 AC 299 ms
14,940 KB
testcase_14 AC 343 ms
15,156 KB
testcase_15 AC 470 ms
15,068 KB
testcase_16 AC 663 ms
15,152 KB
testcase_17 AC 80 ms
15,148 KB
testcase_18 AC 80 ms
15,220 KB
testcase_19 AC 81 ms
15,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
M = N ** 2
ans = 0

1.upto(N) do |x|
  if 2 * (x ** 2) == M
    ans += 1
  else
    ok = N
    ng = 0

    while (ok - ng).abs >= 2
      y = (ok + ng) / 2
      s = x ** 2 + y ** 2

      if s >= M
        ok = y
      else
        ng = y
      end
    end

    if x ** 2 + ok ** 2 == M
      ans += 1
    end
  end
end

puts ans
0