Sherlock and Counting

  • + 1 comment

    Python 3: ans: 1~left root + right root ~n-1

    def solve(n, k):
        if 4*k>=n: return n-1
        x1=(n-math.sqrt(n**2-4*n*k))/2
        x2=(n+math.sqrt(n**2-4*n*k))/2
        return math.floor(x1)+n-math.ceil(x2)