Problem 111747 · easy · Phase 01 Prerequisites & Setup

Largest Power of Two That Fits

loops · while · doubling

Write largest_power_of_two(n) that returns the largest power of two (1, 2, 4, 8, 16, ...) that is less than or equal to n.

Examples

Input:  n = 100
Output: 64

Input:  n = 1
Output: 1

Constraints

  • 1 <= n <= 10**18

Goals

  • Grow a value by doubling inside a while loop
  • Stop one step before overshooting a limit
Starting Python…