For given K and C, choose A > 0 to maximize the characters saved by writing K+A repeated K+A times instead of K repeated K times, minus C times A.
Hard9String matchingMathNumber theoryGreedyNo attempts yetTime limit1sMemory limit128 MBInseop is about to start the homework Hyunwoo gave him. Writing K down K times turned out to be far too much work. While he was thinking it over, Inseop had a good idea. He writes a string in which K+A (A>0) appears K+A times, then convinces Hyunwoo that he solved something harder than the original homework because a larger number appears more often. If this cuts the number of characters he has to write by L, Inseop gains L satisfaction.
Inseop still feels guilty about not solving the homework exactly. If he writes K+A down K+A times instead of writing K down K times, the guilt is proportional to A. Precisely, for a constant C he feels C×A guilt.
Inseop wants to maximize his satisfaction minus his guilt. Find that value.
Numbers may overlap inside the string Inseop writes. For example, 12312 appears twice in the string 12312312, and 3333 appears three times in 333333.
One line contains the two integers K and C from the statement, separated by a space. (1≤K≤1012, 0≤C≤105)
Print the answer on one line. If the value is 0 or less for every positive integer A, print 0.
Take K=10 and C=2. Writing 10 ten times takes 20 characters in total. Writing 11 eleven times takes only 12 characters, so the satisfaction is 8 and the guilt is (11−10)×2. The answer is 8−2=6.