Last active
June 26, 2018 23:42
-
-
Save Ram-Aditya/56ee9fee11a382186199147d3515408e to your computer and use it in GitHub Desktop.
Week 7 Codebuddy
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
def checkSubst(integVal): | |
integVal2=integVal | |
flag=1 | |
while(integVal>1): | |
if(integVal%4!=0): | |
flag=0 | |
break | |
integVal/=4 | |
if(flag): return True | |
while(integVal2>1): | |
if(integVal2%6!=0): | |
return False | |
integVal2/=6 | |
return True | |
bin=input() #100110110 | |
n=len(bin) | |
mem=[] | |
for i in range(n): | |
mem.append(9999999) | |
mem[n-1]= (-1 if(bin[n-1]=="0") else 1 ) | |
for i in range(n-2,-1,-1): | |
if(bin[i]=="0"): | |
mem[i]=-1 | |
continue | |
integVal=0 | |
for j in range(i,n): | |
integVal=2*integVal+(1 if bin[j]=="1" else 0) | |
if(checkSubst(integVal)): | |
if(j==n-1):mem[i]=1 | |
elif(mem[j+1]!=-1):mem[i]=min(mem[i],mem[j+1]+1) | |
if(j==n-1 and mem[i]==9999999):mem[i]=-1 | |
print(mem[0]) |
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
inp=input().split() | |
if inp[0]=="1": | |
print(0) | |
else: | |
z=int(inp[0]) | |
n=int(inp[1]) | |
m=int(inp[2]) | |
sol=1 | |
for i in range(z+m-2,z-2,-1): | |
sol=(sol*i)%1000000007 | |
print(sol%1000000007) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment