问题 D:素数行列

文件提交:无需freopen 内存限制:128 MB 时间限制:1.000 S
评测方式:普通裁判 命题人:
提交:2 解决:2

题目描述

给定一个 lns="http://www.w3.org/1998/Math/MathML">× 的矩阵,其中第 lns="http://www.w3.org/1998/Math/MathML"> 行、第 lns="http://www.w3.org/1998/Math/MathML"> 列的元素的值为 lns="http://www.w3.org/1998/Math/MathML">,。小爱每次可以花费一点代价,将某个元素的值 lns="http://www.w3.org/1998/Math/MathML">+1 。

请问,小爱最少花费多少点代价,才能使得某一行或某一列均为素数?

输入

输入第一行,一个正整数 $n$ 

接下来 $n$ 行,每行 $n$ 个正整数,其中第 $i+1$ 行,第 $j$ 个元素表示 $a_{ij}$

$1\le n\le 1000, 1\le a_{ij}\le 10^5$

输出

输出共一个整数,表示最小代价

样例输入-1 复制

3
5 4 3
1 7 8
9 2 6

样例输出-1 复制

1