Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
ll a, b;
cin>>a>>b;
ll diff = (a >= b) ? (a - b) : (b - a);
if(a > b){
cout<<diff<<" "<<min(diff - (a % diff), b % diff)<<endl;
}
else if(b > a){
cout<<diff<<" "<<min(diff - (b % diff), a % diff)<<endl;
}
else{
cout<<0<<" "<<0<<endl;
}
}
}
Copy The Code &
Try With Live Editor
Input
4
8 5
1 2
4 4
3 9
8 5
1 2
4 4
3 9
Output
3 1
1 0
0 0
a5 6 3
1 0
0 0
a5 6 3
Demonstration
Codeforcess Solution 1543-A A. Exciting Bets ,C++, Java, Js and Python ,1543-A,Codeforcess Solution