#P11968. Minimum Absolute Difference with Specific Binary One Count
Minimum Absolute Difference with Specific Binary One Count
Minimum Absolute Difference with Specific Binary One Count
You are given an integer x. Consider all non‐negative integers y whose binary representation has exactly \(k\) ones. Your task is to find the minimum absolute difference between x and any such y, i.e. compute
[ \min_{\text{popcount}(y)=k} |x-y| ]
Note that the binary representation is taken in its standard form (without leading zeros).
inputFormat
The input consists of two integers x and k separated by a space.
outputFormat
Output a single integer, which is the minimum absolute difference between x and the closest integer y with exactly \(k\) ones in its binary representation.
sample
10 3
1