Perfect P-th Power
Time limit1sMemory limit128 MB
For each nonzero integer x, find the largest exponent p such that x equals some integer raised to the p-th power.
- Level
Medium5 of 10
- Topics
- Number theory, Math, Binary search
- Solved
- No attempts yet
Problem
For an integer , if can be written as then is called a perfect square, and if then is called a perfect cube. In general, if for some integer , then is called a perfect -th power.
Given an integer , write a program that finds the largest integer for which there exists an integer with .
Input
The input consists of several test cases. Each test case is a single line containing one integer . Here , and lies within the signed 32-bit integer range, i.e. .
The line after the last test case contains a single , which is not processed and marks the end of input.
Output
For each test case, print on its own line the largest integer for which there exists an integer with .