Divide by 3 while divisible; or check 319 mod N = 0 (largest power in range).
Complexity: O(√N) or better