eolymp
bolt
Try our new interface for solving problems
Problems

The problem about the chest (Hard)

The problem about the chest (Hard)

Chest named Vova, like all the other chests, dreams of becoming a real safe for his owner. To do this, he wants to make an unusual combination lock. Who wants to open will be given a square matrix with \textbf{N}×\textbf{N }size, filled with random numbers. These numbers need to be made \textit{prime} by using only two operations: \begin{itemize} \item increase the number by \textbf{2} \item decrease the number by \textbf{1} \end{itemize} Recall that a number is called \textit{prime} if it is greater than one and has no divisors other than one and itself. In response, the lock will be necessary to introduce the minimum number of operations that must be performed in order to transform the matrix to the desired form. \InputFile The first line contains the size of the matrix \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{50}). Each of the next \textbf{n} lines contains \textbf{n} integers. This is matrix generated by the lock. To tell you the truth, elements are not entirely random. It is known that each element is non-negative and not greater than \textbf{10^18}. \OutputFile Number, after which the lock will open.
Time limit 3 seconds
Memory limit 64 MiB
Input example #1
3
3 4 9
8 7 10
2 5 6
Output example #1
6
Author Борис Соколов
Source Дистанционная Летняя Компьютерная Школа - лето 2013 года