# 排列硬币(Arrange coins)-其他

## 排列硬币(Arrange coins)

``# 排列硬币# 暴力求解def func1(n: int):    for i in range(1, n + 1):        n -= i        if n < i:            return i# 二分求解def func2(n: int):    low = 1    high = n    while low <= high:        mid = (low + high) // 2        if (mid + 1) * mid / 2 == n:            return mid        elif (mid + 1) * mid / 2 < n:            low = mid + 1        else:            high = mid - 1# 牛顿迭代求解   (i + n/i)/2 <= ndef func3(x: int):    return func(1, x)def func(x: int, n: int):    res = (x + (2*n-x)/x) / 2    if res == x:        return x    else:        return func(res, n)print(func1(10))print(func2(10))print(func3(10))``
————————
``# 排列硬币# 暴力求解def func1(n: int):    for i in range(1, n + 1):        n -= i        if n < i:            return i# 二分求解def func2(n: int):    low = 1    high = n    while low <= high:        mid = (low + high) // 2        if (mid + 1) * mid / 2 == n:            return mid        elif (mid + 1) * mid / 2 < n:            low = mid + 1        else:            high = mid - 1# 牛顿迭代求解   (i + n/i)/2 <= ndef func3(x: int):    return func(1, x)def func(x: int, n: int):    res = (x + (2*n-x)/x) / 2    if res == x:        return x    else:        return func(res, n)print(func1(10))print(func2(10))print(func3(10))``