Search for the maximum in a matrix with a condition
Swift
Medium
loops
Task «Search for the maximum in a matrix with a condition»
Given a square matrix of integers. Find the maximum element among those located above the main diagonal that are prime numbers. If there are no such elements, output -1. A prime number is a natural number greater than 1 that is divisible only by 1 and itself.
Input Format
In the first line, an integer N (1 ≤ N ≤ 100). In the next N lines, N integers each — the elements of the matrix. The absolute values of the numbers do not exceed 1000.
Output Format
One integer — the maximum prime element above the main diagonal, or -1 if there are none.
Examples
Example 1
INPUT
3
2 3 5
7 11 13
17 19 23
OUTPUT
13
Example 2
INPUT
Привет, мир!
OUTPUT
3
Example 3
INPUT
2
4 6
8 10
OUTPUT
-1
Example 4
INPUT
5
1 2 3 4 5
3
OUTPUT
12
Example 5
INPUT
аеёиоуыэюя
OUTPUT
10
main.swift