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 firstname.lastname@example.org. 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find whether a given number is a power of 4 or not
- Check whether a given Number is Power-Isolated or not
- Determine whether the given integer N is a Peculiar Number or not
- Find power of power under mod of a prime
- Find the sum of power of bit count raised to the power B
- Check if given number is a power of d where d is a power of 2
- 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
- Program to find whether a no is power of two
- Compute power of power k times % m
- Larger of a^b or b^a (a raised to power b or b raised to power a)
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Count pairs in Array whose product is a Kth power of any positive integer
- Minimum decrements to make integer A divisible by integer B
- Queries to find whether a number has exactly four distinct factors or not
- Find whether only two parallel lines contain all coordinates points or not
- Check whether a given point lies inside a triangle or not
- Check whether a given matrix is orthogonal or not
- Check whether a given number is Polydivisible or Not
Improved By : nitin mittal