Is it a power?

Write a program to tell if a natural number n is a non-trivial power,
that is, if it can be expressed as x^(m), where both x and m are natural
numbers, and m ≥ 2. For instance, some non-trivial powers are 243 = 3⁵,
400 = 2⁴5² = (2²5¹)², 216000 = 2⁶3³5³ = (2²3¹5¹)³, and
1866240000 = 2¹²3⁶5⁴ = (2⁶3³5²)². By contrast, 3, 200 = 2³5², and
432000 = 2⁷3³5³ are not non-trivial powers.

Input

Input consists of several cases, each with a natural number n between 2
and 10⁶.

Output

Print every n 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.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:06:08.884Z

© Jutge.org, 2006–2026.
https://jutge.org
