PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000144. Ma trận vuông tổng nguyên tố (Prime Square)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ma trận vuông tổng nguyên tố (Prime Square)
Prime Square
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer , construct an square satisfying all conditions:
- Every entry is a nonnegative integer at most .
- No entry is prime.
- The sum of the entries in each row and each column is prime.
Print any valid square.
Input
One line contains integer .
Output
Print exactly lines of integers describing a valid square.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
4
Output
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
Explanation
For , all entries are or , neither of which is prime. Each row contains three ones and one zero, so its sum equals prime . Each column has the same sum . The matrix is valid.