Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
# ABC165c
last = 0


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)
    from math import floor
    

    def dump(*args):
        sys.stderr.write(str(args))

    a, b, n = map(int, input().split())

    def evaluate(number):
        return floor(a*number/b)-a*floor(number/b)
        if number < 100:  
            return 1
        if number == 100:  
            return 0
        if number > 100:  
            return - 1

    def binary_search(low, high):
        global last
        lowest = low
        highest = high
        while low < high:  
            mid = (low + high) // 2
            left = (low + mid) // 2
            right = (mid+high)//2
            lv = evaluate(left)
            rv = evaluate(right)
            mv = evaluate(mid)
            #print(low, high)
            if lv < rv:
                last = max(mv, rv)
                low = mid
                lowest = mid
            else:
                last = max(mv, lv)
                high = mid
                highest = mid
            continue

            if guess == 0:
                return [mid, mid]
            if guess < 0:
                high = mid - 1  
                highest = mid
            else:
                low = mid + 1  
                lowest = mid

        return [lowest, highest]

    t = binary_search(0, n + 1)[0]
    
    print(max(evaluate(t-2), evaluate(t-1), evaluate(t),
              evaluate(t+1), evaluate(t+2), last))


if __name__ == '__main__':
    main()


# ABC165c
last = 0


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)
    from math import floor
    

    def dump(*args):
        sys.stderr.write(str(args))

    a, b, n = map(int, input().split())

    def evaluate(number):
        return floor(a*number/b)-a*floor(number/b)
        if number < 100:  
            return 1
        if number == 100:  
            return 0
        if number > 100:  
            return - 1

    def binary_search(low, high):
        global last
        lowest = low
        highest = high
        while low < high:  
            mid = (low + high) // 2
            left = (low + mid) // 2
            right = (mid+high)//2
            lv = evaluate(left)
            rv = evaluate(right)
            mv = evaluate(mid)
            #print(low, high)
            if lv < rv:
                last = max(mv, rv)
                low = mid
                lowest = mid
            else:
                last = max(mv, lv)
                high = mid
                highest = mid
            continue

            if guess == 0:
                return [mid, mid]
            if guess < 0:
                high = mid - 1  
                highest = mid
            else:
                low = mid + 1  
                lowest = mid

        return [lowest, highest]

    t = binary_search(0, n + 1)[0]
    
    print(max(evaluate(t-2), evaluate(t-1), evaluate(max(n, t)),
              evaluate(max(n, t+1)), evaluate(max(n, t+2)), last))


if __name__ == '__main__':
    main()


# ABC165c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)
    from math import floor
    

    def dump(*args):
        sys.stderr.write(str(args))

    a, b, n = map(int, input().split())
    last = -1
    ans = -1

    def evaluate(number):
        return floor(a * number / b) - a * floor(number / b)

    
    #    print(i, evaluate(i))
    print(max(evaluate(min(b, n)), evaluate(min(b-1, n))))


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Wrong Answer

Accepted