#GL0000291. Điểm nguyên trên đoạn thẳng (Lattice Point or Not)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Điểm nguyên trên đoạn thẳng (Lattice Point or Not)
Lattice Point or Not
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
In the Cartesian plane, a lattice point has both coordinates integral. Two points and are given, each coordinate having exactly one decimal digit. Count all lattice points on the closed line segment , including endpoints if they are lattice points. The endpoints may coincide.
Input
One line containing four decimal numbers in that order.
Output
Print one integer: the number of lattice points on the given segment.
Subtasks
- Subtask 1 (20 points): ; each coordinate has exactly one digit after the decimal point.
- Subtask 2 (30 points): ; each coordinate has exactly one digit after the decimal point.
- Subtask 3 (50 points): ; each coordinate has exactly one digit after the decimal point.
Examples
Example 1
Input
10.1 10.1 11.2 11.2
Output
1
Explanation
The segment lies on , with both coordinates between and . The only integer in that interval is , so the unique lattice point is . Neither endpoint is a lattice point.
Example 2
Input
10.2 100.3 300.3 11.1
Output
0
Explanation
The line through the endpoints satisfies . If and were integers, the left side would be an integer, contradicting the nonintegral right side. Thus the segment contains no lattice point.
Example 3
Input
1.0 1.0 2.0 2.0
Output
2
Explanation
Both endpoints, and , are lattice points and are included. There is no integer strictly between and , so there are no other lattice points on this segment.