CF1283B Candies Division

题目描述

求最大的$ans$,使得$ans\le n$且$ans\equiv r(mod\ k),r\le\lfloor\dfrac{k}{2}\rfloor$。

输入格式

第1行输入1个整数$t(1\le t\le 5·10^4)$,为测试数据组数。 接下来$t$行,每行输入2个整数$n$和$k(1\le n,k\le 10^9)$。

输出格式

$t$行,第$i$行输出第$i$个测试数据的$ans$。

说明/提示

In the first test case, Santa can give $ 3 $ and $ 2 $ candies to kids. There $ a=2, b=3,a+1=3 $ . In the second test case, Santa can give $ 5, 5, 4 $ and $ 4 $ candies. There $ a=4,b=5,a+1=5 $ . The answer cannot be greater because then the number of kids with $ 5 $ candies will be $ 3 $ . In the third test case, Santa can distribute candies in the following way: $ [1, 2, 2, 1, 1, 2, 1] $ . There $ a=1,b=2,a+1=2 $ . He cannot distribute two remaining candies in a way to be satisfied. In the fourth test case, Santa can distribute candies in the following way: $ [3, 3] $ . There $ a=3, b=3, a+1=4 $ . Santa distributed all $ 6 $ candies.