题解 | 二叉树
二叉树
https://www.nowcoder.com/practice/5b80ab166efa4551844657603227caeb
from collections import defaultdict,deque def same_father(a:int,b:int): temp1=a temp2=b while temp1!=temp2: while temp1>temp2 : if temp1%2==1: temp1=(temp1-1)//2 else: temp1=temp1//2 while temp2 > temp1 : if temp2%2==1: temp2=(temp2-1)//2 else: temp2=temp2//2 if temp1>1: return temp1 else: return 1 if __name__=="__main__": while True: try: string=input().split() a,b=int(string[0]),int(string[1]) print(same_father(a,b)) except EOFError: break