def lscan; gets.split.map(&:to_i); end def fsqrt(x) Math.sqrt(x).to_i end def csqrt(x) Math.sqrt(x).ceil.to_i end n,k = lscan abort if n == 0 rn = fsqrt(n) if true c = n/(k*k) h = c*k rem = n - c*(k*k) h += csqrt(rem) p h m = n (n/(k*k)).times do |i| k.times do puts '.'*(k*i)+'#'*k+'.'*(h-(k*i+k)) end m -= k*k end r = rem z = csqrt(rem) z.times do a = [0, [r, z].min].max b = z - a puts '.'*(k*(n/(k*k)))+'#'*a+'.'*b r -= z end end