結果
| 問題 | No.1452 XOR×OR | 
| コンテスト | |
| ユーザー |  yuruhiya | 
| 提出日時 | 2021-04-01 17:48:11 | 
| 言語 | Crystal (1.14.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,224 bytes | 
| コンパイル時間 | 13,105 ms | 
| コンパイル使用メモリ | 297,336 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-02 15:44:05 | 
| 合計ジャッジ時間 | 14,383 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 36 | 
ソースコード
lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end
class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end
struct Int
  def prime_factor : Array(Tuple(self, Int32))
    result = [] of Tuple(self, Int32)
    n = self
    typeof(self).new(2).upto(Math.sqrt(self).ceil) do |x|
      count = 0
      while n % x == 0
        n //= x
        count += 1
      end
      result << {x, count} if count > 0
    end
    result << {n, 1} if n != 1
    result
  end
  def divisors : Array(self)
    result = [] of self
    each_divisor do |d|
      result << d
    end
    result
  end
  def divisor_pairs : Array({self, self})
    divisors.map { |d| {d, self // d} }
  end
  def each_divisor(&)
    tmp = [] of self
    typeof(self).new(1).upto(self) do |x|
      break if x * x > self
      if self % x == 0
        yield x
        tmp << x
      end
    end
    (0...tmp.size).reverse_each do |i|
      yield self // tmp[i] if tmp[i] * tmp[i] < self
    end
  end
end
n = read_line.to_i
puts n.divisor_pairs.sum { |a, b|
  (0...32).reduce(1i64) do |acc, i|
    if a.bit(i) == 1 && b.bit(i) == 1
      acc * 2
    elsif a.bit(i) == 0 && b.bit(i) == 1
      0i64
    else
      acc
    end
  end
} // 2
            
            
            
        