def longmult(x,y)
  result = [0]
  j = 0
  y.digits.each do |m|
    c = 0
    i = j
    x.digits.each do |d|
      v = result[i]
      result << 0 if v.zero?
      c, v = (v + c + d*m).divmod(10)
      result[i] = v
      i += 1
    end
    result[i] += c
    j += 1
  end
  
  result.reverse.inject(0) {|sum, n| 10*sum + n}
end

n=2**64
printf , n, n, n*n
printf , n, n, longmult(n,n)