#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; string s[1010]; int main() { int n, k; cin >> n >> k; if (n <= k * k) { for (int i = 1;; i++) { if (i * i >= n) { int co = 0; cout << i << endl; for (int j = 0; j < i; j++) { for (int k = 0; k < i; k++) { if (co < n) { co++; cout << '#'; } else { cout << '.'; } } cout << endl; } return 0; } } } int ans = (n + k * k - 1) / (k * k); ans *= k; for (int i = 0; i < ans; i++) { s[i] = ""; for (int j = 0; j < ans; j++) { s[i] += '.'; } } for (int i = 0; i < ans; i++) { s[i][i / k * k] = '#'; s[i / k * k][i] = '#'; } for (int i = 1; i < ans; i++) { for (int j = 1; j < ans; j++) { if (s[i - 1][j] == '#' && s[i][j - 1] == '#') { s[i][j] = '#'; } } } int co = 0; for (int i = 0; i < ans; i++) { for (int j = 0; j < ans; j++) { if (s[i][j] == '#') { co++; } } } for (int i = ans - 1; i >= 0; i--) { for (int j = 0; j < ans - i; j++) { if (s[ans - 1 - j][i + j] == '#') { if (co > n) { s[ans - 1 - j][i + j] = '.'; co--; } } } } for (int i = ans - 2; i >= 0; i--) { for (int j = 0; j <= i; j++) { if (s[i - j][j] == '#') { if (co > n) { s[i - j][j] = '.'; co--; } } } } int m = -1; for (int i = 0; i < ans; i++) { for (int j = 0; j < ans; j++) { if (s[i][j] == '#') { if (m < i) { m = i; } if (m < j) { m = j; } } } } cout << m + 1 << endl; for (int i = 0; i <= m; i++) { cout << s[i].substr(0, m + 1) << endl; } }