X, Y = gets.split.map(&:to_i) S = Math.sqrt(X).ceil L = Math.sqrt(Y).floor counter = Hash.new(0) S.upto(L) do |x| counter[x ** 2] += 1 end S.times do |y| dy = y ** 2 S.times do |x| dx = x ** 2 v = dy + dx next if v < X next if Y < v counter[v] += 1 end end if counter.values.empty? puts 0 else puts counter.values.max * 4 end