I want to test if an integer is a perfect power in Pari-gp. The test sqrt(n)==floor(sqrt(n)) works fine for testing squares, but it fails for every other power: sqrtn(n,k)==floor(sqrtn(n,k)) with k >=3.
I think it maybe since one number is real and the other one is integer. Still the test works for squares. What am I doing wrong?
Prime powers have factorizations involving only one base (the prime factor itself). So a better way to perform the test would be:
Here’s a test for the first 10 numbers:
For composite bases, I’ll have to assume you mean that a perfect power factors into some single base raised to an exponent e >= 2. Otherwise any n = n^1. Even now we have corner case of 1 since 1=1^k.
And the test again: