PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000323. Chu kỳ bóng nảy (Bouncing Ball Cycle)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chu kỳ bóng nảy (Bouncing Ball Cycle)

Bouncing Ball Cycle

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

A ball starts at cell (1,1)(1,1) of an n×mn\times m grid and moves diagonally down and right, one cell per step. On reaching a border, the corresponding direction component is reflected. At a corner both components are reflected.

Compute two quantities: the smallest positive number of steps for the ball to return to (1,1)(1,1), and the number of distinct cells it visits between departure and return, counting the starting cell only once.

Input

One line contains integers n,mn,m, the numbers of rows and columns.

Output

Print two integers: the number of steps until the first return and the number of distinct visited cells.

Subtasks

  • Subtask 1 (20 points): 2≤n,m≤102\le n,m\le10.
  • Subtask 2 (30 points): 2≤n,m≤1052\le n,m\le10^5.
  • Subtask 3 (50 points): 2≤n,m≤1092\le n,m\le10^9.

Examples

Example 1

Input

3 4

Output

12 6

Explanation

The row period is 44 and the column period is 66, giving lcm⁡(4,6)=12\operatorname{lcm}(4,6)=12 steps. The six visited cells are (1,1),(2,2),(3,3),(2,4),(1,3),(3,1)(1,1),(2,2),(3,3),(2,4),(1,3),(3,1).

Example 2

Input

2 2

Output

2 2

Explanation

The ball visits (2,2)(2,2) after one step and returns to (1,1)(1,1) after two, visiting two distinct cells.