- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Austin Powers in Python
Suppose we have a number greater than 0, we have to check whether the number is power of two or not.
So, if the input is like 1024, then the output will be True.
To solve this, we will follow these steps −
while n > 1, do
n := n / 2
return true when n is same as 1, otherwise 0
Let us see the following implementation to get better understanding −
class Solution: def solve(self, n): while n > 1: n /= 2 return n == 1 ob = Solution() print(ob.solve(1024))
- Print powers using Anonymous Function in Python?
- Python Program to Get K initial powers of N
- Program to check whether number is a sum of powers of three in Python
- Powers of two and subsequences in C++
- Powers of 2 to required sum in C++
- Return the bases when first array elements are raised to powers from second array in Python
- Print all prime factors and their powers in C++
- C++ Representation of a Number in Powers of Other
- What are the Input Powers of a Synchronous Motor?
- What are the Output Powers of a Synchronous Motor?
- Count ways to express a number as sum of powers in C++
- Balance pans using given weights that are powers of a number in C++ program
- Find k numbers which are powers of 2 and have sum N in C++
- Print all integers that are sum of powers of two given numbers in C++