Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- using namespace std;
- int main(){
- int t; cin >> t;
- while(t--){
- int n, m; cin >> n >> m;
- int big = n, small = n;
- while(big % m != 0) big++;
- while(small % m != 0) small--;
- if(n < 0) swap(big, small);
- int big_diff = abs(big) - abs(n);
- int small_diff = abs(n) - abs(small);
- /*
- cout << big << ' ' << small << endl;
- cout << big_diff << ' ' << small_diff << endl;
- */
- if(big_diff < small_diff) cout << big << endl;
- else if(small_diff < big_diff) cout << small<< endl;
- else if(big_diff == small_diff) {
- int k = max(abs(big), abs(small));
- if(k == abs(big)){
- cout << big << endl;
- }
- else cout << small << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement