problems / 182

The Spinning Beacon and Scanner

easy gcd number-theory math 1000 ms · 256 MB

The Spinning Beacon and Scanner

A lighthouse beacon rotates continuously in a fixed direction, completing one full rotation every p₁ time units. At a coastal monitoring station, a scanner checks the beacon's current direction every p₂ time units.

Both the beacon and scanner start at time 0 in a perfectly aligned state—the beacon is pointing in the direction the scanner is checking. The beacon rotates smoothly without interruption, and the scanner performs its checks at discrete intervals.

After time 0, how many complete rotations will the beacon have made by the time they are aligned again?

Input

The first line contains two integers p₁ and p₂ (1 ≤ p₁, p₂ ≤ 10^9).

Output

Print a single integer: the number of complete rotations the beacon makes before it and the scanner align again.

Notes

The beacon and scanner are aligned again when the time is a common multiple of both p₁ and p₂. The first such time after 0 is their least common multiple.

Example 1

Input

2 3

Output

3

Example 2

Input

4 6

Output

3

Hints · reveal one at a time if you're stuck

Hint 1

The beacon and the scanner line up exactly at the times that are multiples of both periods. What is the first positive such time?

Hint 2

The answer is that time divided by p1, the number of full turns. Think about how the time is built from p1 and p2 and what the two numbers have in common.

Hint 3

Computing the common multiple as p1 times p2 divided by their gcd can overflow 64 bits. Find a way to cancel p1 before you multiply anything.

report an issue Prefer your own editor? sooks prep 182 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.