#include #include int main() { unsigned N, H; std::cin >> N >> H; const auto W = N / H; std::vector res(H, std::vector(W, 0u)); for (auto i = 1u, c = 0u; i < N; ++i) if (N % i == 0) for (auto j = 0u; j < i; ++j, ++c) (W % 2 ? res[c / W][c % W] : res[c % H][c / H]) = i; for (const auto& row : res) { for (const auto& e : row) std::cout << e << ' '; std::cout << '\n'; } }