Loading
Loading
A GPU kernel only accepts batch sizes that are powers of two, so a training script validates the requested size before launching.
Given an integer n, return true if n equals 2ᵏ for some integer k ≥ 0, and false otherwise. Zero and negative numbers are never powers of two.
n = 64n = 1000000one set bitn - 1 = 0111111the set bit cleared, everything below it setn & (n - 1) = 0no bit in common, so n is a power of twotrueSign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
64 = 2⁶.
Example 2
48 = 16 × 3, and the odd factor 3 cannot be halved away.
Example 3
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(1) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
1 = 2⁰ counts.