#SP0000009. Nông dân Feb và vụ khoai tây (Farmer Feb)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nông dân Feb và vụ khoai tây (Farmer Feb)
Farmer Feb
Source: CodeChef
Version: Phuoc Hung OJ Extended
Problem Statement
Farmer Feb grows potatoes in three fields. He has harvested potatoes from the first and from the second. He has not harvested any potatoes from the third field yet. He believes his total harvest will be fortunate if its size is prime. Find the smallest positive number of potatoes he must harvest from the third field so that the total is prime. A prime is an integer greater than with exactly two positive divisors.
Input
One line containing two integers and , the harvests from the first and second fields.
Output
Print the minimum positive integer such that is prime.
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): , .
Examples
Input
1 3
Output
1
Explanation
The first two fields contribute potatoes. Adding gives , which is prime. Since must be positive, is minimal.
Input
4 3
Output
4
Explanation
The initial harvest is . Adding , or gives , and , all composite. Adding gives prime , so is the minimum.