Problem: There are K lemurs on Madagascar and Kevin has N bananas. He has to give away all his bananas to lemurs. Lemurs are happy if all of them get the same number of bananas (even if they don't get any). In one minute Kevin can do one of the following:
 Find one banana. 
 Discard one banana (eat). 
 Increase a population of lemurs on Madagascar by one. 
 If there are at least two lemurs remove one of them from Madagascar (don't ask how). 

Help Kevin and find the minimum number of minutes Kevin needs to satisfy all the lemurs.

Input format:

The only line of the input contains two space-separated integers N and K.

Output format:

Output the single integer -- the minimum number of minutes.

Constraints:
1 ≤ K,N ≤ 10^5
K, N ≤ 50 in test data worth 33% of all points

SAMPLE INPUT
47 17

SAMPLE OUTPUT
2

Solution (in PYTHON):

Solution:
__author__ = 'Prasad'
import re
import math
import sys


def get_distribution(bananas,lemurs):
	div = float(bananas)/float(lemurs)
	mod = math.modf(div)
	if mod[0] < 0.5:
		return int(math.floor(div))
	else:
		return int(math.ceil(div))


if __name__ == "__main__":
	ans = 1000000
	pattern = "(.*) (.*)"
	regex = re.compile(pattern)
	fd = sys.stdin
	line = fd.readline()
	mt = regex.match(line)
	bananas = int(mt.group(1))
	lemurs = int(mt.group(2))
	dist = get_distribution(bananas,lemurs)
	dist_comp = xrange(0,dist+20)
	lemur_comp = xrange(1,lemurs*200/100)
	for no_of_lemurs in lemur_comp:
		for d in dist_comp:
			no_of_bananas = d * no_of_lemurs
			ans_calculated = abs(lemurs - no_of_lemurs) + abs(bananas - no_of_bananas)
			ans = min(ans,ans_calculated)
	print ans