#SP0000051. Ma trận nguyên tố (Prime Matrix)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Ma trận nguyên tố (Prime Matrix)
Prime Matrix
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an matrix of positive integers, one operation increments a chosen cell by exactly . A matrix is prime if some entire row consists of prime numbers or some entire column consists of prime numbers. Find the minimum total number of operations required to make the matrix prime.
Input
The first line contains integers . Each of the next lines contains exactly integers , in column order.
Output
Print the minimum number of operations; print 0 if the matrix already meets the condition.
Subtasks
- Subtask 1 (20 points): ; ; for every cell.
- Subtask 2 (30 points): ; ; for every cell.
- Subtask 3 (50 points): ; ; for every cell.
Examples
Input
3 3
1 2 3
5 6 1
4 4 1
Output
1
Explanation
In the first row, and are prime while is not. Increment the entry at once from to , producing the all-prime row . No row or column was all-prime initially, so the minimum is 1.