Write a program to tell if a natural number is a non-trivial power, that is, if it can be expressed as , where both and are natural numbers, and . For instance, some non-trivial powers are , , , and . By contrast, 3, , and are not non-trivial powers.
Input consists of several cases, each with a natural number between 2 and .
Print every
followed by “yes” or “no”, depending on
whether it is a non-trivial power.
You should not use the mathematical function @pow()@ nor any alike function to solve this problem.
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.
Author: Unknown
Translator: Salvador Roura
Generation: 2026-01-25T11:06:08.884Z
© Jutge.org, 2006–2026.
https://jutge.org