Created
October 11, 2020 13:40
-
-
Save sujaykundu777/8c3924e1f263fb19ca6ab7efef4f7a6a to your computer and use it in GitHub Desktop.
test1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import math | |
import os | |
import random | |
import re | |
import sys | |
def cycleStr(s): | |
return s[-1] + s[:-1] | |
def highestPowerOf2(n): | |
return (n & (~(n - 1))) | |
def powerOf2(n): | |
divData = (math.log10(n) / math.log10(2)) > 0 and (math.log10(n) / math.log10(2)) or 0; | |
return divData; | |
def maximumPower(s): | |
# Write your code here | |
if len(s) > 1: | |
decimalValue = int(s,2) | |
if decimalValue == 7 : | |
val = 0; | |
else: | |
while decimalValue % 2 != 0: | |
s = cycleStr(s) | |
decimalValue = int(s,2) | |
divisibleValue = highestPowerOf2(decimalValue) | |
powerValue = powerOf2(divisibleValue) | |
if powerValue > 100000: | |
val = -1 | |
else: | |
val = math.floor(powerValue); | |
return val | |
else: | |
return 0 | |
if __name__ == '__main__': | |
fptr = open(os.environ['OUTPUT_PATH'], 'w') | |
s = input() | |
result = maximumPower(s) | |
fptr.write(str(result) + '\n') | |
fptr.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment