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.
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.
- Check whether a given number is Polydivisible or Not
- Minimum positive integer divisible by C and is not in range [A, B]
- Length of longest subarray whose sum is not divisible by integer K
- Efficiently check whether n is a multiple of 4 or not
- Check whether the binary equivalent of a number ends with "001" or not
- Check whether a large number is divisible by 53 or not
- Highest power of two that divides a given number
- Smallest integer > 1 which divides every element of the given array
- Check whether given floating point number is even or odd
- Check whether a very large number of the given form is a multiple of 3.
- Quotient and remainder dividing by 2^k (a power of 2)
- Breaking a number such that first part is integral division of second by a power of 10
- Minimum removals in a number to be divisible by 10 power raised to K
- Check if a large number is divisible by a number which is a power of 2
- Count of m digit integers that are divisible by an integer n
- Minimum positive integer to divide a number such that the result is an odd
- To check whether a large number is divisible by 7
- Check whether sum of digits at odd places of a number is divisible by K
- Check whether product of digits at even places of a number is divisible by K
- Find the Kth number which is not divisible by N
Improved By : nitin mittal