-
-
Save g-leech/4c4335c665f47ef83a2913cf9a9eb378 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, math | |
MAX = sys.maxsize | |
MAX_POWER = math.floor(math.log(MAX, 3)) | |
MAX_3 = 3**MAX_POWER | |
def isPowerOf3(x): | |
return MAX_3 % x == 0 | |
print(isPowerOf3(27)) | |
print(isPowerOf3(6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This method isn't actually constant time; the % operator takes longer to execute for different inputs.
Checking this on node: