Dormitory Floor
Time limit1sMemory limit128 MB
Given counts of border tiles and interior tiles of a rectangle grid, find the rectangle's two integer side lengths.
- Level
Medium4 of 10
- Topics
- Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
Sanggeun lives in a dormitory. His room is a rectangle with dimensions L by W.
He wants to cover the whole room with 1×1 tiles. Tiles on the outer border are red, and all remaining interior tiles are brown.
For a 4×3 room, only the border is red and the inside is brown, as shown below.

Hageun saw the tiled floor and remembered only the number of red tiles and the number of brown tiles. Given those two counts, determine the possible room dimensions L and W.
Input
The first line contains the number of red tiles R and the number of brown tiles B, separated by a space.
- 8 ≤ R ≤ 5000
- 1 ≤ B ≤ 2,000,000
Output
Print L and W on one line, separated by a space. If the two dimensions are different, L must be the larger one and W the smaller one. The input is guaranteed to have exactly one answer.