#SP0000218. Đếm số nguyên tố trên hai đường chéo (Elemental Matrix)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm số nguyên tố trên hai đường chéo (Elemental Matrix)
Elemental Matrix
Source: LQDOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an square matrix of nonnegative integers, the main diagonal consists of cells whose row index equals their column index, and the secondary diagonal consists of cells whose row and column indices sum to (using -based indices).
Count the cells lying on at least one of the two diagonals whose values are prime. When is odd, the central cell belongs to both diagonals and must be counted only once.
Input
The first line contains . The next lines each contain integers; line contains describing row .
Output
Print one integer: the number of prime-valued cells on the main or secondary diagonal, counting every cell at most once.
Subtasks
-
Subtask 1 (30 points): ; for all .
-
Subtask 2 (70 points): ; for all .
Examples
Input
3
2 4 5
6 7 8
11 10 13
Output
5
Explanation
In row , the diagonal cells contain and , both prime. Row has the central cell , which belongs to both diagonals but is counted once. Row contributes and , both prime. There are five distinct qualifying cells, with values , so the answer is .