結果

問題 No.939 and or
コンテスト
ユーザー 小野寺健
提出日時 2021-11-08 12:51:02
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 450 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 147 ms
コンパイル使用メモリ 8,832 KB
実行使用メモリ 14,848 KB
最終ジャッジ日時 2026-05-11 03:15:39
合計ジャッジ時間 3,911 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

A, B = gets.split(" ").map{|s| s.to_i}

def bitCount(bits)
	bits = (bits & 0x55555555) + ((bits >> 1) & 0x55555555)
	bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333)
	bits = (bits & 0x0f0f0f0f) + ((bits >> 4) & 0x0f0f0f0f)
	bits = (bits & 0x00ff00ff) + ((bits >> 8) & 0x00ff00ff)
	(bits & 0x0000ffff) + ((bits >> 16) & 0x0000ffff)
end

if A & B != A then
	puts 0
else
	n = bitCount(A ^ B)
	if n < 2 then
		puts 1
	else
		puts 2**(n-1)
	end
end
0