LotsOfLines
SRM 600 · 2013-06-25 · by ir5
Problem Statement
Note that the memory limit for all tasks in this SRM is 256 MB.
You are given
These lines divide the plane into several regions. (Some of them are finite, some are infinite.) Compute and return the total number of regions.
Notes
- Formally, the line with the equation y=ax+b is the set of all points (x,y) such that x is any real number and y=ax+b.
Constraints
- A will be between 1 and 1,200, inclusive.
- B will be between 1 and 1,200, inclusive.
1 1 Returns: 2
There is only one line: y=0. This line divides the plane into two regions.
2 2 Returns: 9
There are four lines. The plane looks as follows.
3 2 Returns: 17
1 1200 Returns: 1201
There are 1,200 horizontal lines.
5 9 Returns: 638
Submissions are judged against all 46 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LotsOfLines with a public method long long countDivisions(int A, int B) · 46 test cases · 2 s / 256 MB per case