CF670D2 Magic Powder - 2

Description

The term of this problem is the same as the previous one, the only exception — increased restrictions.

Input Format

The first line contains two positive integers $ n $ and $ k $ ( $ 1

Output Format

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.