fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t,n,k;
  6. int a,b,c,d;
  7. cin>>t;
  8. while(t--){
  9. cin>>n>>k;
  10. a = n%k;
  11. b = k/2;
  12. if(a>b){
  13. a=a-b;
  14. n = n-a;
  15. cout<<n<<endl;
  16. }
  17. else{
  18. cout<<n<<endl;
  19. }
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 4300KB
stdin
6
5  2
19  4
12  7
6  2  
100000  50010
5  7
stdout
5
18
10
6
75015
3