Perfect P-th Power

Time limit1sMemory limit128 MB

Summary
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 bb, if xx can be written as x=b2x = b^2 then xx is called a perfect square, and if x=b3x = b^3 then xx is called a perfect cube. In general, if x=bpx = b^p for some integer bb, then xx is called a perfect pp-th power.

Given an integer xx, write a program that finds the largest integer pp for which there exists an integer bb with x=bpx = b^p.

Input

The input consists of several test cases. Each test case is a single line containing one integer xx. Here ∣x∣≥2|x| \ge 2, and xx lies within the signed 32-bit integer range, i.e. −2147483648≤x≤2147483647-2147483648 \le x \le 2147483647.

The line after the last test case contains a single 00, which is not processed and marks the end of input.

Output

For each test case, print on its own line the largest integer pp for which there exists an integer bb with x=bpx = b^p.

Examples2

  1. Example 1

    Input
    17
    1073741824
    25
    0
    
    Expected output
    1
    30
    2
    
  2. Example 2

    Input
    -8
    -27
    -32
    0
    
    Expected output
    3
    3
    5