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

#GL0000194. Ước lớn nhất không chia hết (Division)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Ước lớn nhất không chia hết (Division)

Ước lớn nhất không chia hết (Division)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given integers p,qp,q, find the largest positive integer xx such that xx divides pp but qq does not divide xx.

Input

One line with pp and qq.

Output

Print the maximum valid xx.

Subtasks

  • Subtask 1 (20 points): 1≤p≤10000001\le p\le 1000000; 2≤q≤100002\le q\le 10000.

  • Subtask 2 (30 points): 1≤p≤10000000000001\le p\le 1000000000000; 2≤q≤10000002\le q\le 1000000.

  • Subtask 3 (50 points): 1≤p≤10000000000000000001\le p\le 1000000000000000000; 2≤q≤10000000002\le q\le 1000000000.

Examples

Example 1

Input

12 6

Output

4

Explanation

Both 1212 and 66 are divisible by 66. The largest divisor of 1212 that is not divisible by 66 is 44.

Example 2

Input

10 4

Output

10

Explanation

Since 1010 is not divisible by 44, the greatest divisor of 1010, namely itself, already satisfies the condition.

Example 3

Input

179 822

Output

179

Explanation

Since 822822 does not divide 179179, the optimal answer is 179179.