Given an integer, how can I detect the nearest integer perfect power efficiently?

1.9k Views Asked by At

If you give me an integer N, how can I detect the nearest integer perfect power, larger or smaller than N?

In other words, the perfect power the distance between N and which is less than the distance between N and any other perfect power. Exponents of 1 are excluded. Prime or composite powers are ok.

This is not a homework question. Is there a method that is better than some kind of neighborhood door knock method? 'Hello, are you a perfect power? No, okay.'