結果

問題 No.638 Sum of "not power of 2"
ユーザー simansiman
提出日時 2020-11-30 18:29:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 83 ms / 1,000 ms
コード長 241 bytes
コンパイル時間 68 ms
コンパイル使用メモリ 11,464 KB
実行使用メモリ 15,348 KB
最終ジャッジ日時 2023-10-11 02:58:07
合計ジャッジ時間 2,332 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,020 KB
testcase_01 AC 81 ms
15,160 KB
testcase_02 AC 80 ms
15,188 KB
testcase_03 AC 80 ms
15,296 KB
testcase_04 AC 82 ms
15,128 KB
testcase_05 AC 82 ms
15,148 KB
testcase_06 AC 81 ms
15,136 KB
testcase_07 AC 79 ms
15,316 KB
testcase_08 AC 81 ms
15,348 KB
testcase_09 AC 83 ms
15,044 KB
testcase_10 AC 82 ms
15,264 KB
testcase_11 AC 82 ms
15,228 KB
testcase_12 AC 81 ms
15,236 KB
testcase_13 AC 80 ms
15,168 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:21: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

N = gets.to_i

def is_power_of_2(x)
  while x > 1
    return false if x % 2 == 1
    x /= 2
  end

  true
end

1.upto(200) do |a|
  next if is_power_of_2(a)
  b = N - a
  next if is_power_of_2(b)

  puts [a, b].join(' ')
  exit
end

puts -1
0