Is it a power? P51271


Statement
 

pdf   zip

Write a program to tell if a natural number nn is a non-trivial power, that is, if it can be expressed as xmx^m, where both xx and mm are natural numbers, and m2m \ge 2. For instance, some non-trivial powers are 243=35243 = 3^5, 400=2452=(2251)2400 = 2^4 5^2 = (2^2 5^1)^2, 216000=263353=(223151)3216000 = 2^6 3^3 5^3 = (2^2 3^1 5^1)^3, and 1866240000=2123654=(263352)21866240000 = 2^{12} 3^6 5^4 = (2^6 3^3 5^2)^2. By contrast, 3, 200=2352200 = 2^3 5^2, and 432000=273353432000 = 2^7 3^3 5^3 are not non-trivial powers.

Input

Input consists of several cases, each with a natural number nn between 2 and 10610^6.

Output

Print every nn followed by “yes” or “no”, depending on whether it is a non-trivial power.

Observation

You should not use the mathematical function @pow()@ nor any alike function to solve this problem.

Hint

A possible solution uses a variant of the sieve of Eratosthenes to precompute a prime factor of each number before starting to read the input.

Public test cases
  • Input

    243
    400
    216000
    3
    200
    432000
    1000000
    999999
    

    Output

    243 yes
    400 yes
    216000 yes
    3 no
    200 no
    432000 no
    1000000 yes
    999999 no
    
  • Information
    Author
    Jordi Cortadella
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++