N, K = map(int, input().split()) q, r = divmod(N, K * K) R = int(r ** 0.5) if R * R < r: R += 1 M = K * q + R G = [["." for _ in range(M)] for _ in range(M)] for i in range(0, M - R, K): j = i for di in range(K): for dj in range(K): if 0 <= i + di < M and 0 <= j + dj < M: G[i + di][j + dj] = "#" count = 0 for i in range(R): for j in range(R): if count >= r: break if i > K or j > K: continue G[K * q + i][K * q + j] = "#" count += 1 print(M) for g in G: print("".join(g))