#include using namespace std; using ll = long long; int calc(int n, int K, vector& v) { if (n <= 0) return 0; if (n >= K * K) { v.push_back(K); return calc(n - K * K, K, v) + K; } int res = 1; for (int i = 1; i <= K; i++) { if (n <= i * i) { res = i; break; } } v.push_back(res); return calc(n - res * res, K, v) + res; } bool judge(vector& ans, int n, int K) { int m = ans.size(); for (int i = 0; i < m; i++) { int tmp = 0; for (int j = 0; j < m; j++) { tmp += (ans[i][j] == '#'); } if (tmp > K) return false; } int cnt = 0; for (int j = 0; j < m; j++) { int tmp = 0; for (int i = 0; i < m; i++) { tmp += (ans[i][j] == '#'); cnt += (ans[i][j] == '#'); } if (tmp > K) return false; } return (cnt == n); } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, K; cin >> n >> K; assert(K <= 3); vector v; int m = calc(n, K, v); cout << m << "\n"; vector ans(m, string(m, '.')); int rest = n; int beg = 0; for (int x : v) { for (int i = beg; i < beg + x; i++) { for (int j = beg; j < beg + x; j++) { if (rest == 0) continue; ans[i][j] = '#'; rest--; } } beg += x; } for (int i = 0; i < m; i++) { cout << ans[i] << "\n"; } assert(judge(ans, n, K)); return 0; }