10: Binary Numbers ( python)

                           Binary Numbers ( python)                          

Task

Given a base- integer, , convert it to binary (base-). Then find and print the base- integer denoting the maximum number of consecutive 's in 's binary representation.

Input Format

A single integer, .

Constraints

Output Format

Print a single base- integer denoting the maximum number of consecutive 's in the binary representation of .

solution :

#!/bin/python3

import math
import os
import random
import re
import sys

if __name__ == '__main__':

  n = int(input())

max_one_count = 0
one_count = 0

while n != 0:
    factor = n // 2
    remainder = n - 2 * factor
    n = factor
    if remainder == 1:
        one_count += 1
        max_one_count = max(max_one_count, one_count)
    else:
        one_count = 0

print(max_one_count)

Comments

Popular posts from this blog

15: Linked List(python)