結果

問題 No.1452 XOR×OR
ユーザー simansiman
提出日時 2021-04-14 03:00:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 1,111 ms
コンパイル使用メモリ 11,184 KB
実行使用メモリ 15,600 KB
最終ジャッジ日時 2023-09-15 12:23:32
合計ジャッジ時間 5,521 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
15,176 KB
testcase_01 AC 92 ms
15,392 KB
testcase_02 AC 91 ms
15,264 KB
testcase_03 AC 90 ms
15,276 KB
testcase_04 AC 90 ms
15,384 KB
testcase_05 AC 91 ms
15,196 KB
testcase_06 AC 92 ms
15,200 KB
testcase_07 AC 91 ms
15,388 KB
testcase_08 AC 91 ms
15,360 KB
testcase_09 AC 91 ms
15,196 KB
testcase_10 AC 90 ms
15,312 KB
testcase_11 AC 90 ms
15,384 KB
testcase_12 AC 89 ms
15,360 KB
testcase_13 AC 90 ms
15,508 KB
testcase_14 AC 89 ms
15,368 KB
testcase_15 AC 91 ms
15,396 KB
testcase_16 AC 90 ms
15,080 KB
testcase_17 AC 91 ms
15,528 KB
testcase_18 AC 90 ms
15,396 KB
testcase_19 AC 90 ms
15,244 KB
testcase_20 AC 90 ms
15,428 KB
testcase_21 AC 89 ms
15,516 KB
testcase_22 AC 89 ms
15,272 KB
testcase_23 AC 91 ms
15,508 KB
testcase_24 AC 91 ms
15,600 KB
testcase_25 AC 89 ms
15,304 KB
testcase_26 AC 90 ms
15,508 KB
testcase_27 AC 93 ms
15,500 KB
testcase_28 AC 90 ms
15,364 KB
testcase_29 AC 91 ms
15,392 KB
testcase_30 AC 91 ms
15,412 KB
testcase_31 AC 90 ms
15,392 KB
testcase_32 AC 91 ms
15,424 KB
testcase_33 AC 91 ms
15,552 KB
testcase_34 AC 90 ms
15,216 KB
testcase_35 AC 89 ms
15,344 KB
testcase_36 AC 92 ms
15,360 KB
testcase_37 AC 95 ms
15,312 KB
testcase_38 AC 91 ms
15,292 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Integer
  def divisor_list
    require 'prime'

    return [] if self <= 0
    return [1] if self == 1

    prime_division.map.with_index { |(base, k), i|
      s = i.zero? ? 0 : 1
      (s..k).map { |n| base ** n }
    }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort
  end
end

N = gets.to_i
ans = 0

N.divisor_list.each do |x|
  o = N / x
  cnt = 0

  l = [x.bit_length, o.bit_length].max
  l.times do |i|
    if x[i] == 1 && o[i] == 1
      cnt += 1
    elsif x[i] == 1 && o[i] == 0
      cnt = -1
      break
    elsif x[i] == 0 && o[i] == 0
      # noop
    elsif x[i] == 0 && o[i] == 0
      # noop
    end
  end

  ans += 2 ** (cnt - 1) if 0 <= cnt
end

puts ans
0