#SP0000110. Đếm điểm nguyên nguyên tố trên chu vi (Chef and Polygons)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm điểm nguyên nguyên tố trên chu vi (Chef and Polygons)
Chef and Polygons
Source: CodeChef
Version: Phuoc Hung OJ Extended
Problem Statement
A simple polygon is formed by connecting the integer-coordinate vertices in the stated order and closing the last edge to the first vertex. Edges do not cross. An integer lattice point has both coordinates integral. Count all lattice points on the polygon boundary for which is prime. Each point must be counted once, including vertices shared by adjacent edges.
Input
The first line contains , the number of vertices.
The second line contains integers .
The third line contains integers . The -th values on the latter two lines form vertex .
Output
Print one integer: the number of boundary lattice points with prime coordinate sum.
Subtasks
Let denote the Euclidean perimeter of the polygon.
- Subtask 1 (20 points): ; for every vertex; ; vertices in the given order form a simple polygon.
- Subtask 2 (30 points): ; for every vertex; ; vertices in the given order form a simple polygon.
- Subtask 3 (50 points): ; for every vertex; ; vertices in the given order form a simple polygon.
Examples
Input
4
1 5 5 1
1 1 4 4
Output
7
Explanation
The vertices are . The three qualifying points along the bottom are , , and . One additional point on the right is ; two on the top are and ; one on the left is . Their coordinate sums are all prime. Every corner is counted once, giving .