46. Biggest Square Tile (GCD)

Acceptance — 0 accepted 0 submissions

Easy
GCDLoopsMath
No companies listed
A contractor wants to cover a rectangular floor of size L × B with square tiles, all of the same size, without cutting any tile.

Find the side of the biggest square tile that fits perfectly, and how many such tiles are needed.
The biggest side is the GCD (greatest common divisor) of L and B.

Input Format
A single line with two integers L and B.

Output Format
Print the tile side on the first line and the number of tiles on the second line.

Constraints
• 1 ≤ L, B ≤ 10^6

Example 1

Input
12 8
Output
4
6

Explanation GCD of 12 and 8 is 4. Tiles: (12/4) × (8/4) = 3 × 2 = 6.

Example 2

Input
7 5
Output
1
35

Explanation 7 and 5 share no common factor except 1, so 35 tiles of size 1.

Example 3

Input
10 10
Output
10
1

Explanation A square floor needs just one big tile.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
4 6
No results yet
Run your code to test it against the sample cases.
Problem List