結果

問題 No.638 Sum of "not power of 2"
ユーザー mai
提出日時 2018-01-26 22:30:04
言語 Ruby
(3.4.1)
結果
AC  
実行時間 95 ms / 1,000 ms
コード長 281 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-12-30 02:19:14
合計ジャッジ時間 2,428 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:11: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:22: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

def ascan; gets.split.map(&:to_i);end


def bitcount(x)
    return x.to_s(2).count("1")
end

n = gets.to_i

if n == 1
    p -1
    exit
end

1.upto([n-1,1000].min) do |a|
    b = n-a
    if bitcount(b) != 1 && bitcount(a) != 1
        puts "#{a} #{b}"
        exit
    end
end
p -1
0