def handshakes(n:int):
res=0
for i in range(1,n+1):
res=res+i
if res>=n:
return i+1
#思路:n个人不重复互相握手的最大次数是可以计算的n-1+n-2+...+1,只要握手次数小于这个值,且大于n-1个人的最大握手次数,就输出n
def handshakes(n: int) -> int:
if n==0:
return 1
index = 1
while True:
if index*(index-1)//2 >= n and (index-1)*(index-2)//2 < n:
break
index += 1
return index
def handshakes(n: int) -> int:
num = 2
while True:
handshake_list = [(i, j) for i in range(1, num + 1) for j in range(i + 1, num + 1)]
if len(handshake_list) >= n:
return num
num += 1
assert handshakes(1) == 2
assert handshakes(3) == 3
assert handshakes(6) == 4
assert handshakes(7) == 5
def handshakes(n: int) -> int:
for renshu in range(n+1):
shakesCountS = sum([i for i in range(1,renshu+1)])
shakesCountM = sum([i for i in range(1,renshu+2)])
if n >shakesCountS and n <=shakesCountM:
return renshu+2
assert handshakes(1) == 2
assert handshakes(3) == 3
assert handshakes(6) == 4
assert handshakes(7) == 5