Given a positive integer, write a function to find if it is a power of three or not.
Input : 3 Output :Yes Input :6 Output :No
The logic is very simple. Any integer number other than power of 3 which divides highest power of 3 value that integer can hold 3^19 = 1162261467 (Assuming that integers are stored using 32 bits) will give reminder non-zero.
Time Complexity : O(1)
This article is contributed by Jebasingh and Riyazath. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find ways an Integer can be expressed as sum of n-th power of unique natural numbers
- Highest power of 2 less than or equal to given Integer
- Elements of Array which can be expressed as power of some integer to given exponent K
- Find the sum of power of bit count raised to the power B
- Count pairs in Array whose product is a Kth power of any positive integer
- Find power of power under mod of a prime
- Find value of y mod (2 raised to power x)
- Program to find whether a no is power of two
- Find whether a given number is a power of 4 or not
- Given two numbers as strings, find if one is a power of other
- Find the super power of a given Number
- Find unit digit of x raised to power y
- Find multiple of x closest to or a ^ b (a raised to power b)
- Find last five digits of a given five digit number raised to power five
- Find maximum power of a number that divides a factorial
Improved By : nitin mittal