This page is still under construction.

Parts of this page are still being built. What you see may change.

Let's Solve a Geometry Problem

Interview

Time limit2sMemory limit512 MB

Summary
Given a fraction p/q, find the smallest base b >= 2 in which p/q has a finite (terminating) expansion.
Level

Medium6 of 10

Topics
Number theory, Math, Implementation, Sorting
Solved
No attempts yet

Problem

A is solving a geometry problem again today. When solving geometry problems, it is important to be careful of floating-point errors.

A floating-point error is an error caused by rounding that occurs when a number is represented as a finite binary fraction. For example, 0.10.1 in decimal is the infinite binary fraction 0.00011001100110011...0.00011001100110011 ..., and rounding this to a finite number of digits produces an error.

Positive integers pp and qq are given in decimal. Find a base bb (bb is an integer greater than or equal to 2) in which the rational number pp / qq can be represented as a finite decimal. If there are multiple such bases, output the smallest one.

Input

The input is given from standard input in the following format.

pp qq

Output

Output the answer on one line.

Constraints

  • 0<p<q<1090 < p < q < 10^9

Examples2

  1. Example 1

    Input
    1 2
    
    Expected output
    2
    
  2. Example 2

    Input
    21 30
    
    Expected output
    10