Let's Solve a Geometry Problem
InterviewTime limit2sMemory limit512 MB
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, in decimal is the infinite binary fraction , and rounding this to a finite number of digits produces an error.
Positive integers and are given in decimal. Find a base ( is an integer greater than or equal to 2) in which the rational number / 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.
Output
Output the answer on one line.