output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while(t--) { long long a,b; cin >> a >> b; if(a==b) cout << 0 << " " << 0 << '\n'; else { long long g = abs(a-b); long long m = min(a%g,g-a%g); cout << g << " " << m << '\n'; } } }
### Prompt Please create a solution in Cpp to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while(t--) { long long a,b; cin >> a >> b; if(a==b) cout << 0 << " " << 0 << '\n'; else { long long g = abs(a-b); long long m = min(a%g,g-a%g); cout << g << " " << m << '\n'; } } } ```
#include<bits/stdc++.h> using namespace std; #define ll long long #define FAST1 ios_base::sync_with_stdio(false); #define FAST2 cin.tie(NULL); void solve() { ll a,b; cin>>a>>b; ll ans=abs(a-b); if(ans==0) { cout<<"0 0"; } else cout<<ans<<" "<<min(a%ans,ans-a%ans); } int main(){ FAST1; FAST2; int t; cin>>t; while(t--) { solve(); cout<<endl; } }
### Prompt Create a solution in cpp for the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define ll long long #define FAST1 ios_base::sync_with_stdio(false); #define FAST2 cin.tie(NULL); void solve() { ll a,b; cin>>a>>b; ll ans=abs(a-b); if(ans==0) { cout<<"0 0"; } else cout<<ans<<" "<<min(a%ans,ans-a%ans); } int main(){ FAST1; FAST2; int t; cin>>t; while(t--) { solve(); cout<<endl; } } ```
#include<bits/stdc++.h> #define ll long long using namespace std; int main(){ ios::sync_with_stdio(false);cout.tie(0);cin.tie(0); int te; cin>>te; while(te--){ ll a,b; cin>>a>>b; if(a<b) swap(a,b); if(a==b){ cout<<"0 0\n"; }else{ ll t=a-b; cout<<t<<' '<<min(b%t,t-b%t)<<'\n'; } } return 0; }
### Prompt Your task is to create a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> #define ll long long using namespace std; int main(){ ios::sync_with_stdio(false);cout.tie(0);cin.tie(0); int te; cin>>te; while(te--){ ll a,b; cin>>a>>b; if(a<b) swap(a,b); if(a==b){ cout<<"0 0\n"; }else{ ll t=a-b; cout<<t<<' '<<min(b%t,t-b%t)<<'\n'; } } return 0; } ```
#include <stdio.h> int main() { int t; scanf("%d", &t); while(t--) { long long int a, b; scanf("%lld", &a); scanf("%lld", &b); if(a == 0) { printf("%lld 0\n", b); }else if(b==0) { printf("%lld 0\n", a); }else if(a == b) { printf("0 0\n"); } else{ long long int ans = a-b; if(ans < 0) ans *= -1; long long int ans1 = (ans - (a%ans)); long long int ans2 = (a%ans); if(a % ans == 0) printf("%lld 0\n", ans); else if(ans2 < ans1) printf("%lld %lld\n", ans, ans2); else printf("%lld %lld\n", ans, ans1); } } return 0; }
### Prompt Your challenge is to write a CPP solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <stdio.h> int main() { int t; scanf("%d", &t); while(t--) { long long int a, b; scanf("%lld", &a); scanf("%lld", &b); if(a == 0) { printf("%lld 0\n", b); }else if(b==0) { printf("%lld 0\n", a); }else if(a == b) { printf("0 0\n"); } else{ long long int ans = a-b; if(ans < 0) ans *= -1; long long int ans1 = (ans - (a%ans)); long long int ans2 = (a%ans); if(a % ans == 0) printf("%lld 0\n", ans); else if(ans2 < ans1) printf("%lld %lld\n", ans, ans2); else printf("%lld %lld\n", ans, ans1); } } return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; long long otv[t][2]; for (long long i=0; i<t; i++) { long long a,b; cin >> a >> b; if (a==b) { otv[i][0]=0; otv[i][1]=0; } else { if (a>b) { long long v=a; a=b; b=v; } long long ras=b-a; if (ras==1) { otv[i][0]=1; otv[i][1]=0; } else { long long res=min(a%ras,ras-(a%ras)); otv[i][0]=ras; otv[i][1]=res; } } } for (int i=0; i<t; i++) { cout << otv[i][0] << " " << otv[i][1] << endl; } }
### Prompt Please create a solution in CPP to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; long long otv[t][2]; for (long long i=0; i<t; i++) { long long a,b; cin >> a >> b; if (a==b) { otv[i][0]=0; otv[i][1]=0; } else { if (a>b) { long long v=a; a=b; b=v; } long long ras=b-a; if (ras==1) { otv[i][0]=1; otv[i][1]=0; } else { long long res=min(a%ras,ras-(a%ras)); otv[i][0]=ras; otv[i][1]=res; } } } for (int i=0; i<t; i++) { cout << otv[i][0] << " " << otv[i][1] << endl; } } ```
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ long long int a,b; cin>>a>>b; long long int diff = abs(a-b); long long int moves = 0; if(a==b) cout<<0<<" "<<0<<"\n"; else{ if(a>diff) moves = a%diff; else moves = b%diff; if(moves>diff/2) moves = diff-moves; if(a==0){ diff = b; moves = 0; } else if(b==0){ diff = a; moves = 0; } else if(a%b==0 && b>=diff){ diff = b; moves = 0; } else if(b%a==0 && a>=diff){ diff = a; moves = 0; } cout<<diff<<" "<<moves<<"\n"; } } return 0; }
### Prompt Please formulate a cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ long long int a,b; cin>>a>>b; long long int diff = abs(a-b); long long int moves = 0; if(a==b) cout<<0<<" "<<0<<"\n"; else{ if(a>diff) moves = a%diff; else moves = b%diff; if(moves>diff/2) moves = diff-moves; if(a==0){ diff = b; moves = 0; } else if(b==0){ diff = a; moves = 0; } else if(a%b==0 && b>=diff){ diff = b; moves = 0; } else if(b%a==0 && a>=diff){ diff = a; moves = 0; } cout<<diff<<" "<<moves<<"\n"; } } return 0; } ```
#include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ long long a, b; cin>>a>>b; if(a==b){ cout<<0<<' '<<0<<endl; }else{ long long c=abs(a-b); long long d=min(a%c, c-a%c); cout<<c<<' '<<d<<endl; } } }
### Prompt Please provide a CPP coded solution to the problem described below: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ long long a, b; cin>>a>>b; if(a==b){ cout<<0<<' '<<0<<endl; }else{ long long c=abs(a-b); long long d=min(a%c, c-a%c); cout<<c<<' '<<d<<endl; } } } ```
#include <iostream> #include <math.h> #include <algorithm> using namespace std; int main() { int t; cin >> t; while(t--){ long long a,b; cin >> a >> b; if(a == b){ cout << 0 << " " << 0 << endl; } else{ long long exc = abs(a-b); long long num = min(a%exc, exc - a%exc); cout << exc << " " << num << endl; } } }
### Prompt Construct a Cpp code solution to the problem outlined: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <iostream> #include <math.h> #include <algorithm> using namespace std; int main() { int t; cin >> t; while(t--){ long long a,b; cin >> a >> b; if(a == b){ cout << 0 << " " << 0 << endl; } else{ long long exc = abs(a-b); long long num = min(a%exc, exc - a%exc); cout << exc << " " << num << endl; } } } ```
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define PB push_back #define MP make_pair #define PPB pop_back int gcd(int a, int b){ if(b==0) return a; return gcd(b,a%b); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; cin>>t; while (t--){ ll a,b; cin>>a>>b; if(a==b){ cout<<"0 0"<<endl; continue; } ll m=abs(a-b); ll n=min(a%m,m-a%m); cout<<m<<" "<<n<<endl; } return 0; }
### Prompt Please formulate a CPP solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; typedef long long int ll; #define PB push_back #define MP make_pair #define PPB pop_back int gcd(int a, int b){ if(b==0) return a; return gcd(b,a%b); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; cin>>t; while (t--){ ll a,b; cin>>a>>b; if(a==b){ cout<<"0 0"<<endl; continue; } ll m=abs(a-b); ll n=min(a%m,m-a%m); cout<<m<<" "<<n<<endl; } return 0; } ```
#include<iostream> #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define ff first #define ss second #define MOD 1000000007 // void func(){ // } void solution(){ ll a,b; cin>>a>>b; ll val = abs(a-b); if(val==0){ cout<<"0 0"<<endl; return; } ll count = min(val-(a%val),a%val); cout<<val<<" "<<count<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; cin>>t; // func(); while(t--){ solution(); } return 0; }
### Prompt Generate a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<iostream> #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define ff first #define ss second #define MOD 1000000007 // void func(){ // } void solution(){ ll a,b; cin>>a>>b; ll val = abs(a-b); if(val==0){ cout<<"0 0"<<endl; return; } ll count = min(val-(a%val),a%val); cout<<val<<" "<<count<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; cin>>t; // func(); while(t--){ solution(); } return 0; } ```
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { // freopen("file.in", "r", stdin); int t; cin >> t; while(t--){ ll a, b; cin>>a>>b; if(a == b) { cout<<0<<' '<<0<<'\n'; continue; } cout<<abs(a-b)<<' '; cout<<min(a%abs(a-b), abs(a-b) - a%abs(a-b))<<'\n'; } }
### Prompt Please create a solution in cpp to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> #define ll long long using namespace std; int main() { // freopen("file.in", "r", stdin); int t; cin >> t; while(t--){ ll a, b; cin>>a>>b; if(a == b) { cout<<0<<' '<<0<<'\n'; continue; } cout<<abs(a-b)<<' '; cout<<min(a%abs(a-b), abs(a-b) - a%abs(a-b))<<'\n'; } } ```
#include<bits/stdc++.h> using namespace std; const int N=100200; typedef long long ll; int main(){ ll t; ll a, b, k, mi; cin>>t; while(t--){ cin>>a>>b; if(b>a)swap(a,b); if(a==b)cout<<"0 0"<<endl; else{ k=a-b; mi=min(a%k,k-a%k); cout<<k<<" "<<mi<<endl; } } return 0; }
### Prompt Your task is to create a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; const int N=100200; typedef long long ll; int main(){ ll t; ll a, b, k, mi; cin>>t; while(t--){ cin>>a>>b; if(b>a)swap(a,b); if(a==b)cout<<"0 0"<<endl; else{ k=a-b; mi=min(a%k,k-a%k); cout<<k<<" "<<mi<<endl; } } return 0; } ```
#include<bits/stdc++.h> #define int long long #define pb push_back #define MAX INT_MAX #define MIN INT_MIN #define fr(a,b) for(int i = a; i < b; i++) #define rep(i,a,b) for(int i = a; i < b; i++) #define mod 1000000007 #define all(x) (x).begin(), (x).end() #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL) using namespace std; void solve(){ int a,b; cin >> a >> b; int ans=abs(a-b); if(a==b){ cout << "0 0\n"; } else{ if(a%ans==0 && b%ans==0){ cout << ans << " 0\n"; } else{ cout << ans << " " << min(a%ans,ans-a%ans) << "\n"; } } } signed main() { fast_io; // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t = 1; cin >> t; while(t--){ solve(); } return 0; }
### Prompt Create a solution in CPP for the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> #define int long long #define pb push_back #define MAX INT_MAX #define MIN INT_MIN #define fr(a,b) for(int i = a; i < b; i++) #define rep(i,a,b) for(int i = a; i < b; i++) #define mod 1000000007 #define all(x) (x).begin(), (x).end() #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL) using namespace std; void solve(){ int a,b; cin >> a >> b; int ans=abs(a-b); if(a==b){ cout << "0 0\n"; } else{ if(a%ans==0 && b%ans==0){ cout << ans << " 0\n"; } else{ cout << ans << " " << min(a%ans,ans-a%ans) << "\n"; } } } signed main() { fast_io; // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t = 1; cin >> t; while(t--){ solve(); } return 0; } ```
#include <bits/stdc++.h> using namespace std; #define ll long long int main(){ ll t; cin>>t; while(t--){ ll n,k; cin>>n>>k; if(abs(n-k)==0){ cout<<0<<" "<<0<<endl; continue; } ll p=abs(n-k); cout<<p<<" "<<min({n%p, k%p, p-(n%p), p-(k%p)})<<endl; } return 0; }
### Prompt Construct a Cpp code solution to the problem outlined: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; #define ll long long int main(){ ll t; cin>>t; while(t--){ ll n,k; cin>>n>>k; if(abs(n-k)==0){ cout<<0<<" "<<0<<endl; continue; } ll p=abs(n-k); cout<<p<<" "<<min({n%p, k%p, p-(n%p), p-(k%p)})<<endl; } return 0; } ```
#include <iostream> #include <fstream> #include <map> #include <vector> #include <algorithm> #include <queue> #include <cmath> #define MAX_N 10002 #define mp make_pair #define pb push_back #define pii pair<int,int> typedef long long ll; using namespace std; int main(){ int t; cin >> t; while(t--){ ll a,b; cin >> a >> b; if(a==b){ cout << "0 0" << endl; continue; } if(a<b) swap(a,b); ll c = a-b; cout << c << " " << min(a%c,c-a%c) << endl; } return 0; }
### Prompt Create a solution in CPP for the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <iostream> #include <fstream> #include <map> #include <vector> #include <algorithm> #include <queue> #include <cmath> #define MAX_N 10002 #define mp make_pair #define pb push_back #define pii pair<int,int> typedef long long ll; using namespace std; int main(){ int t; cin >> t; while(t--){ ll a,b; cin >> a >> b; if(a==b){ cout << "0 0" << endl; continue; } if(a<b) swap(a,b); ll c = a-b; cout << c << " " << min(a%c,c-a%c) << endl; } return 0; } ```
#include <iostream> using namespace std; long long int gcd(long long int a, long long int b) { if (a == 0) return b; if (b == 0) { return a; } if (a == b) return a; if (a > b) return gcd(a-b, b); return gcd(a, b-a); } int main() { int t; cin>>t; while(t--) { long long int a,b; cin>>a>>b; if(a==b) { cout<<0<<" "<<0<<endl; }else if (a>b) { long long int k = a-b; long long int n = a%k; if(n==0) { cout<<gcd(a,b)<<" "<<0<<endl; }else if(k-n>n) { cout<<gcd(a-n,b-n)<<" "<<n<<endl; }else{ cout<<gcd(a+k-n,b+k-n)<<" "<<k-n<<endl; } }else{ long long int k = b-a; long long int n = b%k; if(n==0) { cout<<gcd(a,b)<<" "<<0<<endl; }else if(k-n>n) { cout<<gcd(a-n,b-n)<<" "<<n<<endl; }else{ cout<<gcd(a+k-n,b+k-n)<<" "<<k-n<<endl; } } } }
### Prompt Create a solution in Cpp for the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <iostream> using namespace std; long long int gcd(long long int a, long long int b) { if (a == 0) return b; if (b == 0) { return a; } if (a == b) return a; if (a > b) return gcd(a-b, b); return gcd(a, b-a); } int main() { int t; cin>>t; while(t--) { long long int a,b; cin>>a>>b; if(a==b) { cout<<0<<" "<<0<<endl; }else if (a>b) { long long int k = a-b; long long int n = a%k; if(n==0) { cout<<gcd(a,b)<<" "<<0<<endl; }else if(k-n>n) { cout<<gcd(a-n,b-n)<<" "<<n<<endl; }else{ cout<<gcd(a+k-n,b+k-n)<<" "<<k-n<<endl; } }else{ long long int k = b-a; long long int n = b%k; if(n==0) { cout<<gcd(a,b)<<" "<<0<<endl; }else if(k-n>n) { cout<<gcd(a-n,b-n)<<" "<<n<<endl; }else{ cout<<gcd(a+k-n,b+k-n)<<" "<<k-n<<endl; } } } } ```
#include <iostream> using namespace std; #include<bits/stdc++.h> #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--) { ll a,b,d; cin>>a>>b; if(a==b) { cout<<0<<" "<<0<<"\n"; } else if(abs(a-b)==1) { cout<<1<<" "<<0<<"\n"; } else { d=abs(a-b); ll prv=(a/d)*d; ll next=((a/d)+1)*d; ll ans=min((next-a),(a-prv)); cout<<d<<" "<<ans<<"\n"; } } }
### Prompt Please provide a Cpp coded solution to the problem described below: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <iostream> using namespace std; #include<bits/stdc++.h> #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--) { ll a,b,d; cin>>a>>b; if(a==b) { cout<<0<<" "<<0<<"\n"; } else if(abs(a-b)==1) { cout<<1<<" "<<0<<"\n"; } else { d=abs(a-b); ll prv=(a/d)*d; ll next=((a/d)+1)*d; ll ans=min((next-a),(a-prv)); cout<<d<<" "<<ans<<"\n"; } } } ```
#include <iostream> using namespace std; #include<bits/stdc++.h> #define ll long long ll closestMultiple(ll n, ll x) { if(x>n) return x; n = n + x/2; n = n - (n%x); return n; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--) { ll a,b,d; cin>>a>>b; if(a==b) { cout<<0<<" "<<0<<"\n"; } else if(abs(a-b)==1) { cout<<1<<" "<<0<<"\n"; } else { d=abs(a-b); ll p=min(abs(a-closestMultiple(a,d)),abs(b-closestMultiple(b,d))); cout<<d<<" "<<min(p,min(a,b))<<"\n"; } } }
### Prompt Generate a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <iostream> using namespace std; #include<bits/stdc++.h> #define ll long long ll closestMultiple(ll n, ll x) { if(x>n) return x; n = n + x/2; n = n - (n%x); return n; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--) { ll a,b,d; cin>>a>>b; if(a==b) { cout<<0<<" "<<0<<"\n"; } else if(abs(a-b)==1) { cout<<1<<" "<<0<<"\n"; } else { d=abs(a-b); ll p=min(abs(a-closestMultiple(a,d)),abs(b-closestMultiple(b,d))); cout<<d<<" "<<min(p,min(a,b))<<"\n"; } } } ```
#include<bits/stdc++.h> using namespace std; #define ll long long #define loopf(i,a,b) for(int i=a;i<b;i++) #define loopb(i,a,b) for(int i=a;i>b;i--) #define pb push_back #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define ff first #define ss second #define vc vector #define vii vector<int> #define vll vector<long long> #define pii pair<int,int> #define pll pair<ll,ll> //General defs #define umap unordered_map #define uset unordered_set //Along with data types #define mapii map<int,int> #define mapll map<ll,ll> #define seti set<int> #define setll set<ll> #define umapii unordered_map<int,int> #define useti unordered_set<int> #define umapll unordered_map<ll,ll> #define usetll unordered_set<ll> #define all(x) x.begin(),x.end() #define endl "\n" #define ld long double const ll M=1e9+7; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl #define imax INT_MAX #define imin INT_MIN #define lmax LLONG_MAX #define lmin LLONG_MIN void solve(){ ll a,b; cin>>a>>b; if(a==b) { cout<<"0 0\n"; return; } if(a>b) swap(a,b); if(a==0) { cout<<b<<" "<<0<<endl; return; } cout<<abs(a-b)<<" "<<min(a%abs(a-b),min(a,abs(a-b)-a%(b-a)))<<endl; } int main() { bool take_test_cases=1; fast; if(take_test_cases) { int t; cin>>t; while(t--) solve(); } else solve(); }
### Prompt In Cpp, your task is to solve the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define ll long long #define loopf(i,a,b) for(int i=a;i<b;i++) #define loopb(i,a,b) for(int i=a;i>b;i--) #define pb push_back #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define ff first #define ss second #define vc vector #define vii vector<int> #define vll vector<long long> #define pii pair<int,int> #define pll pair<ll,ll> //General defs #define umap unordered_map #define uset unordered_set //Along with data types #define mapii map<int,int> #define mapll map<ll,ll> #define seti set<int> #define setll set<ll> #define umapii unordered_map<int,int> #define useti unordered_set<int> #define umapll unordered_map<ll,ll> #define usetll unordered_set<ll> #define all(x) x.begin(),x.end() #define endl "\n" #define ld long double const ll M=1e9+7; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl #define imax INT_MAX #define imin INT_MIN #define lmax LLONG_MAX #define lmin LLONG_MIN void solve(){ ll a,b; cin>>a>>b; if(a==b) { cout<<"0 0\n"; return; } if(a>b) swap(a,b); if(a==0) { cout<<b<<" "<<0<<endl; return; } cout<<abs(a-b)<<" "<<min(a%abs(a-b),min(a,abs(a-b)-a%(b-a)))<<endl; } int main() { bool take_test_cases=1; fast; if(take_test_cases) { int t; cin>>t; while(t--) solve(); } else solve(); } ```
#include <iostream> using namespace std; using ll = long long; void solve() { ll a, b; cin >> a >> b; if (a == b ) { cout << "0 0\n"; return; } ll dif = abs(a-b); ll up = a%dif; if (up > dif - up) { cout << dif << " " << dif - up << endl; } else { cout << dif << " " << up << endl; } } int main() { ll t = 1; cin >> t; while (t--) { solve(); } return 0; }
### Prompt Your challenge is to write a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <iostream> using namespace std; using ll = long long; void solve() { ll a, b; cin >> a >> b; if (a == b ) { cout << "0 0\n"; return; } ll dif = abs(a-b); ll up = a%dif; if (up > dif - up) { cout << dif << " " << dif - up << endl; } else { cout << dif << " " << up << endl; } } int main() { ll t = 1; cin >> t; while (t--) { solve(); } return 0; } ```
#include <bits/stdc++.h> #define x first #define y second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { ll a, b; cin >> a >> b; if (a == b) cout << "0 0\n"; else { ll n = abs(a - b); cout << n << ' '; if (a % n == 0) cout << "0\n"; else cout << min(a % n, n - a % n) << '\n'; } } return 0; }
### Prompt Please provide a Cpp coded solution to the problem described below: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> #define x first #define y second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { ll a, b; cin >> a >> b; if (a == b) cout << "0 0\n"; else { ll n = abs(a - b); cout << n << ' '; if (a % n == 0) cout << "0\n"; else cout << min(a % n, n - a % n) << '\n'; } } return 0; } ```
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define pll pair<ll,ll> #define pii pair<int,int> #define vll vector<ll> #define vi vector<int> #define sz(v) (ll)v.size() #define all(v) v.begin(),v.end() #define pq_max priority_queue<ll> #define pq_min priority_queue <ll, vector<ll>, greater<ll> > #define debug(x) cout<<#x<<"->"<<x<<endl #define debug2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<"->"<<y<<endl #define debug3(x,y,z) cout<<#x<<"->"<<x<<", "<<#y<<"->"<<y<<","<<#z<<"->"<<z<<endl #define endl '\n' #define ff first #define ss second const ll INF = 4000000000000000000; const ll mod = 1000000007; const ll prime1 = 1999999973, prime2 = 1999999943; void read(vll& arr,ll n){ for(int i=0;i<n;i++) cin>>arr[i]; } ll solve(){ ll a,b; cin>>a>>b; if(a>b) swap(a,b); if(a==b){ cout<<"0 0\n"; return 0; } if(a==0){ cout<<b<<" 0\n"; return 0; } b-=a; ll ans1,ans2; if(a<=b){ ans1=b; ans2=min(b-a,a); } else{ ans1=b; ans2=min(a%b,b-(a%b)); } cout<<ans1<<" "<<ans2<<endl; return 0; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("minima.in","r",stdin); // freopen("minima.out","w",stdout); ll T=1; cin>>T; for(int i=1;i<=T;i++){ //cout<<"Case #"<< i <<":"; solve(); //cout<<endl; } return 0; }
### Prompt Construct a cpp code solution to the problem outlined: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define pll pair<ll,ll> #define pii pair<int,int> #define vll vector<ll> #define vi vector<int> #define sz(v) (ll)v.size() #define all(v) v.begin(),v.end() #define pq_max priority_queue<ll> #define pq_min priority_queue <ll, vector<ll>, greater<ll> > #define debug(x) cout<<#x<<"->"<<x<<endl #define debug2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<"->"<<y<<endl #define debug3(x,y,z) cout<<#x<<"->"<<x<<", "<<#y<<"->"<<y<<","<<#z<<"->"<<z<<endl #define endl '\n' #define ff first #define ss second const ll INF = 4000000000000000000; const ll mod = 1000000007; const ll prime1 = 1999999973, prime2 = 1999999943; void read(vll& arr,ll n){ for(int i=0;i<n;i++) cin>>arr[i]; } ll solve(){ ll a,b; cin>>a>>b; if(a>b) swap(a,b); if(a==b){ cout<<"0 0\n"; return 0; } if(a==0){ cout<<b<<" 0\n"; return 0; } b-=a; ll ans1,ans2; if(a<=b){ ans1=b; ans2=min(b-a,a); } else{ ans1=b; ans2=min(a%b,b-(a%b)); } cout<<ans1<<" "<<ans2<<endl; return 0; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("minima.in","r",stdin); // freopen("minima.out","w",stdout); ll T=1; cin>>T; for(int i=1;i<=T;i++){ //cout<<"Case #"<< i <<":"; solve(); //cout<<endl; } return 0; } ```
#include <bits/stdc++.h> #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } #define sz(x) (int)x.size() #define all(x) x.begin(),x.end() using namespace std; using ll = long long; void err(istream_iterator<string> it) {cerr << endl;} template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);} const int dx[] = {0, -1, 1, 0, 1, -1, 1, -1}; const int dy[] = {1 , 0, 0, -1, 1, -1, -1, 1}; const int mod = 1e9 + 7; const int N = 1e5 + 5; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q; cin >> q; while(q--){ ll a , b; cin >> a >> b; ll ans = abs(a-b); if(a == b){ cout << 0 << ' ' << 0 << '\n'; continue; } ll c = (a / ans); ll d = ((a + ans - 1) / ans); if(d * ans - a <= a - c * ans){ cout << ans << ' ' << (d * ans - a) << '\n'; }else{ cout << ans << ' ' << (a - c * ans) << '\n'; } } return 0; }
### Prompt Generate a cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } #define sz(x) (int)x.size() #define all(x) x.begin(),x.end() using namespace std; using ll = long long; void err(istream_iterator<string> it) {cerr << endl;} template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);} const int dx[] = {0, -1, 1, 0, 1, -1, 1, -1}; const int dy[] = {1 , 0, 0, -1, 1, -1, -1, 1}; const int mod = 1e9 + 7; const int N = 1e5 + 5; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q; cin >> q; while(q--){ ll a , b; cin >> a >> b; ll ans = abs(a-b); if(a == b){ cout << 0 << ' ' << 0 << '\n'; continue; } ll c = (a / ans); ll d = ((a + ans - 1) / ans); if(d * ans - a <= a - c * ans){ cout << ans << ' ' << (d * ans - a) << '\n'; }else{ cout << ans << ' ' << (a - c * ans) << '\n'; } } return 0; } ```
#include<iostream> using namespace std; #define long long long int main() { long tt; cin>>tt; while(tt--) { long a,b; cin>>a>>b; long h1,m1; h1=abs(a-b); if(h1==0) { cout<<0<<" "<<0<<endl; } else if(a==0 || b==0) { cout<<max(a,b)<<" "<<0<<endl; } else { m1=min(a%h1,h1-a%h1); cout<<h1<<" "<<m1<<endl; } } }
### Prompt Your challenge is to write a CPP solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<iostream> using namespace std; #define long long long int main() { long tt; cin>>tt; while(tt--) { long a,b; cin>>a>>b; long h1,m1; h1=abs(a-b); if(h1==0) { cout<<0<<" "<<0<<endl; } else if(a==0 || b==0) { cout<<max(a,b)<<" "<<0<<endl; } else { m1=min(a%h1,h1-a%h1); cout<<h1<<" "<<m1<<endl; } } } ```
#include <bits/stdc++.h> #define endl '\n' //pls remove while debugging #define ll long long int using namespace std; void solve() { ll a, b; cin>>a>>b; if (a == b) { cout<<0<<" "<<0<<endl; return; } ll dif = abs(a-b); cout<<abs(a - b)<<" "<<min(a%dif, dif- a%dif)<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; cin >> t; while (t--) solve(); return 0; }
### Prompt Develop a solution in Cpp to the problem described below: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> #define endl '\n' //pls remove while debugging #define ll long long int using namespace std; void solve() { ll a, b; cin>>a>>b; if (a == b) { cout<<0<<" "<<0<<endl; return; } ll dif = abs(a-b); cout<<abs(a - b)<<" "<<min(a%dif, dif- a%dif)<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; cin >> t; while (t--) solve(); return 0; } ```
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define inf 1e18+5 #define mod 1000000007 #define MAXN 100005 #define ll long long #define pb push_back #define sortv(v) sort(v.begin(),v.end()) #define tc(t) int t;cin>>t;while(t--) #define copy copy_n #define fr(i,a,b) for(long long i=a;i<b;i++) #define frr(i,a,b) for(long long i=a;i>=b;i--) #define frn(i,a,b,n) for(long long i=a;i<=b;i=i+n) #define gcd(x,y) __gcd(x,y) #define lcm(x,y) (x*y)/gcd(x,y) #define ld long double #define um unordered_map #define mkp make_pair #define b_s binary_search #define nob __builtin_popcount #define des greater<ll>() #define fi first #define se second ll mul(ll a, ll b, ll p = mod) {return ((a % p) * (b % p)) % p;} ll add(ll a, ll b, ll p = mod) {return (a % p + b % p) % p;} void input(ll a[], ll sz) {fr(i, 0, sz) cin >> a[i];} void print(ll a[], ll sz) {fr(i, 0, sz) {if (i == sz - 1) cout << a[i] << "\n"; else cout << a[i] << " ";}} ll maxr(ll a[], ll sz) {ll ma; fr(i, 0, sz) {if (i == 0) ma = a[i]; else if (a[i] > ma) ma = a[i];} return ma;} ll minr(ll a[], ll sz) {ll mi; fr(i, 0, sz) {if (i == 0) mi = a[i]; else if (a[i] < mi) mi = a[i];} return mi;} ll isprm(ll n) { if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return 0; return 1; } /*ll spf[MAXN]; void sieve() { spf[1]=1; for (ll i=2; i<MAXN; i++) spf[i] = i; for (ll i=4; i<MAXN; i+=2) spf[i] = 2; for(ll i=3;i*i<MAXN;i+=2) { if (spf[i]==i) { for (int j=i*i;j<MAXN;j+=i) if (spf[j]==j) spf[j]=i; } } }*/ ll power(ll x, ll y, ll p = mod) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } ll modInverse(ll n, ll p = mod) { return power(n, p - 2, p); } /*ll fac[MAXN]; ll inv[MAXN]; void fact(ll p=mod) { fac[0] = 1; for (ll i = 1 ; i < MAXN; i++) fac[i] = fac[i - 1] * i % p; for(ll i=0;i<MAXN;i++) inv[i]=modInverse(fac[i]); } ll ncrMod(ll n, ll r, ll p = mod) { if (r == 0) return 1; return (fac[n] * inv[r] % p * inv[n-r] % p) % p; }*/ //a+b=xor(a,b)+2*(a&b)// struct comp { bool operator()(const pair<ll, ll> &a, const pair<ll, ll> &b)const { if (a.fi == b.fi) { return (a.se > b.se); //second elem in descending } return (a.first < b.first);//first elem in ascending } }; int main() { fio; tc(t) { ll a,b; cin>>a>>b; ll d=abs(b-a); if(d==0) { cout<<"0 0\n"; continue; } ll r=a%d; cout<<d<<" "<<min(r,d-r)<<"\n"; } return 0; }
### Prompt Please formulate a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define inf 1e18+5 #define mod 1000000007 #define MAXN 100005 #define ll long long #define pb push_back #define sortv(v) sort(v.begin(),v.end()) #define tc(t) int t;cin>>t;while(t--) #define copy copy_n #define fr(i,a,b) for(long long i=a;i<b;i++) #define frr(i,a,b) for(long long i=a;i>=b;i--) #define frn(i,a,b,n) for(long long i=a;i<=b;i=i+n) #define gcd(x,y) __gcd(x,y) #define lcm(x,y) (x*y)/gcd(x,y) #define ld long double #define um unordered_map #define mkp make_pair #define b_s binary_search #define nob __builtin_popcount #define des greater<ll>() #define fi first #define se second ll mul(ll a, ll b, ll p = mod) {return ((a % p) * (b % p)) % p;} ll add(ll a, ll b, ll p = mod) {return (a % p + b % p) % p;} void input(ll a[], ll sz) {fr(i, 0, sz) cin >> a[i];} void print(ll a[], ll sz) {fr(i, 0, sz) {if (i == sz - 1) cout << a[i] << "\n"; else cout << a[i] << " ";}} ll maxr(ll a[], ll sz) {ll ma; fr(i, 0, sz) {if (i == 0) ma = a[i]; else if (a[i] > ma) ma = a[i];} return ma;} ll minr(ll a[], ll sz) {ll mi; fr(i, 0, sz) {if (i == 0) mi = a[i]; else if (a[i] < mi) mi = a[i];} return mi;} ll isprm(ll n) { if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return 0; return 1; } /*ll spf[MAXN]; void sieve() { spf[1]=1; for (ll i=2; i<MAXN; i++) spf[i] = i; for (ll i=4; i<MAXN; i+=2) spf[i] = 2; for(ll i=3;i*i<MAXN;i+=2) { if (spf[i]==i) { for (int j=i*i;j<MAXN;j+=i) if (spf[j]==j) spf[j]=i; } } }*/ ll power(ll x, ll y, ll p = mod) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } ll modInverse(ll n, ll p = mod) { return power(n, p - 2, p); } /*ll fac[MAXN]; ll inv[MAXN]; void fact(ll p=mod) { fac[0] = 1; for (ll i = 1 ; i < MAXN; i++) fac[i] = fac[i - 1] * i % p; for(ll i=0;i<MAXN;i++) inv[i]=modInverse(fac[i]); } ll ncrMod(ll n, ll r, ll p = mod) { if (r == 0) return 1; return (fac[n] * inv[r] % p * inv[n-r] % p) % p; }*/ //a+b=xor(a,b)+2*(a&b)// struct comp { bool operator()(const pair<ll, ll> &a, const pair<ll, ll> &b)const { if (a.fi == b.fi) { return (a.se > b.se); //second elem in descending } return (a.first < b.first);//first elem in ascending } }; int main() { fio; tc(t) { ll a,b; cin>>a>>b; ll d=abs(b-a); if(d==0) { cout<<"0 0\n"; continue; } ll r=a%d; cout<<d<<" "<<min(r,d-r)<<"\n"; } return 0; } ```
#pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } ostream &operator<<(ostream &os, const set<int> &se){ os << '{'; int now = 0; for(auto x : se){ if(now) { os << ','; } os << x; now++; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<double> vd; typedef pair<ll,ll> P; typedef pair<int,int> pii; typedef vector<P> vpl; typedef tuple<ll,ll,ll> tapu; #define rep(i,n) for(int i=0; i<(n); i++) #define REP(i,a,b) for(int i=(a); i<(b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = (1<<30)-1; const ll linf = 1LL<<61; const int MAX = 510000; int dy[8] = {0,1,0,-1,1,-1,-1,1}; int dx[8] = {-1,0,1,0,1,-1,1,-1}; const double pi = acos(-1); const double eps = 1e-7; template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){ if(a>b){ a = b; return true; } else return false; } template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){ if(a<b){ a = b; return true; } else return false; } template<typename T> inline void print(T &a){ int sz = a.size(); for(auto itr = a.begin(); itr != a.end(); itr++){ cout << *itr; sz--; if(sz) cout << " "; } cout << "\n"; } template<typename T1,typename T2> inline void print2(T1 a, T2 b){ cout << a << " " << b << "\n"; } template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){ cout << a << " " << b << " " << c << "\n"; } void mark() {cout << "#" << "\n";} ll pcount(ll x) {return __builtin_popcountll(x);} const int mod = 1e9 + 7; //const int mod = 998244353; void solve(){ ll a,b; cin >> a >> b; if(a > b) swap(a,b); ll ans = b-a; if(ans == 0){ cout << "0 0\n"; return; } ll r = a % ans; cout << ans << " " << min(r,ans-r) << "\n"; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int t = 1; cin >> t; while(t--){ solve(); } }
### Prompt Develop a solution in cpp to the problem described below: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } ostream &operator<<(ostream &os, const set<int> &se){ os << '{'; int now = 0; for(auto x : se){ if(now) { os << ','; } os << x; now++; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<double> vd; typedef pair<ll,ll> P; typedef pair<int,int> pii; typedef vector<P> vpl; typedef tuple<ll,ll,ll> tapu; #define rep(i,n) for(int i=0; i<(n); i++) #define REP(i,a,b) for(int i=(a); i<(b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = (1<<30)-1; const ll linf = 1LL<<61; const int MAX = 510000; int dy[8] = {0,1,0,-1,1,-1,-1,1}; int dx[8] = {-1,0,1,0,1,-1,1,-1}; const double pi = acos(-1); const double eps = 1e-7; template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){ if(a>b){ a = b; return true; } else return false; } template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){ if(a<b){ a = b; return true; } else return false; } template<typename T> inline void print(T &a){ int sz = a.size(); for(auto itr = a.begin(); itr != a.end(); itr++){ cout << *itr; sz--; if(sz) cout << " "; } cout << "\n"; } template<typename T1,typename T2> inline void print2(T1 a, T2 b){ cout << a << " " << b << "\n"; } template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){ cout << a << " " << b << " " << c << "\n"; } void mark() {cout << "#" << "\n";} ll pcount(ll x) {return __builtin_popcountll(x);} const int mod = 1e9 + 7; //const int mod = 998244353; void solve(){ ll a,b; cin >> a >> b; if(a > b) swap(a,b); ll ans = b-a; if(ans == 0){ cout << "0 0\n"; return; } ll r = a % ans; cout << ans << " " << min(r,ans-r) << "\n"; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int t = 1; cin >> t; while(t--){ solve(); } } ```
#include<bits/stdc++.h> using namespace std; #define ll long long int main(){ ll t; cin >> t; while (t--){ ll a, b; cin >> a >> b; if(a == b) cout << "0 0" << endl; else{ ll mE = abs(a - b); ll mA; ll x1 = (a/mE + 1) * mE - a; ll x2 = a - (a/mE) * mE; mA = min(x1, x2); cout << mE << " " << mA << endl; } } return 0; }
### Prompt Create a solution in cpp for the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define ll long long int main(){ ll t; cin >> t; while (t--){ ll a, b; cin >> a >> b; if(a == b) cout << "0 0" << endl; else{ ll mE = abs(a - b); ll mA; ll x1 = (a/mE + 1) * mE - a; ll x2 = a - (a/mE) * mE; mA = min(x1, x2); cout << mE << " " << mA << endl; } } return 0; } ```
#include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define all(x) x.begin() , x.end() #define ld long double #define debug(x) cout << #x << " = " << x << "\n" const long long inf = 1e18 + 5LL; const int inf32 = INT_MAX; const int mod = 998244353 ; //1e9 + 7LL; const int N = (1e6 + 10); void solve(int t); void solve(); void ITO(); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ITO(); int t = 1; cin >> t; for (int i = 0; i < t; i++) solve(i + 1); return 0; } void solve(int TcNumber) { int a , b; cin >> a >> b; if (a < b) swap(a , b); int gcd = a - b; int m = 0; if (gcd > 0) { int up = (b + gcd - 1) / gcd; int down = b / gcd; m = min(up * gcd - b , b - (down * gcd)); } cout << gcd << " " << m; cout << "\n"; return ; } void solve() {} void ITO() { #ifndef ONLINE_JUDGE freopen("inputf.in", "r", stdin); freopen("output.txt", "w", stdout); #endif }
### Prompt Your task is to create a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define all(x) x.begin() , x.end() #define ld long double #define debug(x) cout << #x << " = " << x << "\n" const long long inf = 1e18 + 5LL; const int inf32 = INT_MAX; const int mod = 998244353 ; //1e9 + 7LL; const int N = (1e6 + 10); void solve(int t); void solve(); void ITO(); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ITO(); int t = 1; cin >> t; for (int i = 0; i < t; i++) solve(i + 1); return 0; } void solve(int TcNumber) { int a , b; cin >> a >> b; if (a < b) swap(a , b); int gcd = a - b; int m = 0; if (gcd > 0) { int up = (b + gcd - 1) / gcd; int down = b / gcd; m = min(up * gcd - b , b - (down * gcd)); } cout << gcd << " " << m; cout << "\n"; return ; } void solve() {} void ITO() { #ifndef ONLINE_JUDGE freopen("inputf.in", "r", stdin); freopen("output.txt", "w", stdout); #endif } ```
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll t; cin>>t; while(t--) { ll a,b; cin>>a>>b; if(a==b) { cout<<"0"<<" "<<"0"<<endl; } else{ ll g=abs(a-b); cout<<g<<" "; cout<<min(a%g,g-a%g)<<endl; } } }
### Prompt Generate a CPP solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll t; cin>>t; while(t--) { ll a,b; cin>>a>>b; if(a==b) { cout<<"0"<<" "<<"0"<<endl; } else{ ll g=abs(a-b); cout<<g<<" "; cout<<min(a%g,g-a%g)<<endl; } } } ```
#include <bits/stdc++.h> using namespace std; typedef long long ll; void testcase () { ll a, b; cin >> a >> b; if (a < b) swap (a, b); if (a == b) { puts ("0 0"); return; } ll diff = a - b; cout << diff << ' ' << min (a % diff, diff - (a % diff)) << "\n"; return; } int main () { int t = 1; cin >> t; while (t--) { testcase(); } return 0; }
### Prompt Your challenge is to write a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; typedef long long ll; void testcase () { ll a, b; cin >> a >> b; if (a < b) swap (a, b); if (a == b) { puts ("0 0"); return; } ll diff = a - b; cout << diff << ' ' << min (a % diff, diff - (a % diff)) << "\n"; return; } int main () { int t = 1; cin >> t; while (t--) { testcase(); } return 0; } ```
#include<bits/stdc++.h> #define ll long long #define int ll #define pb push_back #define INF 1e18 #define MOD 1000000007 #define mp make_pair #define REP(i,n) for (int i = 0; i < n; i++) #define FOR(i,a,b) for (int i = a; i < b; i++) #define REPD(i,n) for (int i = n-1; i >= 0; i--) #define FORD(i,a,b) for (int i = a; i >= b; i--) #define umap unordered_map #define pii pair<int,int> #define F first #define S second #define mii map<int,int> #define vi vector<int> #define vvi vector<vi> #define itr :: iterator it #define all(v) v.begin(),v.end() #define WL(t) while(t--) #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) #define out(x) cout << #x << " is " << x <<"\n" #define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); using namespace std; void solve() { int a, b; cin>>a>>b; if(a==b) { cout<<"0 0"; return; } int c=abs(a-b); cout<<c<<" "<<min(a%c, c-a%c); } signed main() { FastIO int t=1; cin>>t; WL(t){ solve(); if(t!=0) cout<<"\n"; } return 0; }
### Prompt Your challenge is to write a CPP solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> #define ll long long #define int ll #define pb push_back #define INF 1e18 #define MOD 1000000007 #define mp make_pair #define REP(i,n) for (int i = 0; i < n; i++) #define FOR(i,a,b) for (int i = a; i < b; i++) #define REPD(i,n) for (int i = n-1; i >= 0; i--) #define FORD(i,a,b) for (int i = a; i >= b; i--) #define umap unordered_map #define pii pair<int,int> #define F first #define S second #define mii map<int,int> #define vi vector<int> #define vvi vector<vi> #define itr :: iterator it #define all(v) v.begin(),v.end() #define WL(t) while(t--) #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) #define out(x) cout << #x << " is " << x <<"\n" #define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); using namespace std; void solve() { int a, b; cin>>a>>b; if(a==b) { cout<<"0 0"; return; } int c=abs(a-b); cout<<c<<" "<<min(a%c, c-a%c); } signed main() { FastIO int t=1; cin>>t; WL(t){ solve(); if(t!=0) cout<<"\n"; } return 0; } ```
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef pair<ll,ll> pll; #define F first #define S second #define PB push_back #define MP make_pair #define all(x) x.begin(),x.end() #define foru(i, a, b) for(ll i=a; i < (b) ; i++) #define fore(i, a, b) for(ll i=a ; i <= (b); i++) const ll mod = 1e9+7, N = 2e6+7, M = 2e6+7, INF = INT_MAX/10; ll power(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;} ll str_to_int(string s){stringstream asteya(s); ll x=0; asteya>>x; return x;} string int_to_str(ll n){return to_string(n);} void testcase(){ ll a,b,ans,moves,sub; cin>>a>>b; if(a==0 and b==0) cout<<0<<" "<<0<<endl; else{ ans = abs(a-b); if(ans == 0) sub=0; else sub = min(a,b)%ans; if(ans > 0 && ans !=1) moves = min(sub, (ans-(a%ans))%ans); else moves = 0; cout<<ans<<" "<<moves<<endl; } } int main(){ fast; int t=1; cin >> t; while(t--){ testcase(); } return 0; }
### Prompt Please provide a cpp coded solution to the problem described below: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef pair<ll,ll> pll; #define F first #define S second #define PB push_back #define MP make_pair #define all(x) x.begin(),x.end() #define foru(i, a, b) for(ll i=a; i < (b) ; i++) #define fore(i, a, b) for(ll i=a ; i <= (b); i++) const ll mod = 1e9+7, N = 2e6+7, M = 2e6+7, INF = INT_MAX/10; ll power(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;} ll str_to_int(string s){stringstream asteya(s); ll x=0; asteya>>x; return x;} string int_to_str(ll n){return to_string(n);} void testcase(){ ll a,b,ans,moves,sub; cin>>a>>b; if(a==0 and b==0) cout<<0<<" "<<0<<endl; else{ ans = abs(a-b); if(ans == 0) sub=0; else sub = min(a,b)%ans; if(ans > 0 && ans !=1) moves = min(sub, (ans-(a%ans))%ans); else moves = 0; cout<<ans<<" "<<moves<<endl; } } int main(){ fast; int t=1; cin >> t; while(t--){ testcase(); } return 0; } ```
#include<bits/stdc++.h> using namespace std; #define int long long void solve(){ int a, b; cin >> a >> b; if (a == b) { cout << "0 0\n"; return; } if (a < b) swap(a, b); if (!b) { cout << a << ' ' << 0 << '\n'; return; } int d = a - b; int x = b % d; cout << d << ' ' << min(x, d - x) << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifdef local freopen("inp.txt","r",stdin); freopen("out.txt","w",stdout); #endif int test; cin >> test; while (test--) solve(); }
### Prompt Please provide a Cpp coded solution to the problem described below: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define int long long void solve(){ int a, b; cin >> a >> b; if (a == b) { cout << "0 0\n"; return; } if (a < b) swap(a, b); if (!b) { cout << a << ' ' << 0 << '\n'; return; } int d = a - b; int x = b % d; cout << d << ' ' << min(x, d - x) << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifdef local freopen("inp.txt","r",stdin); freopen("out.txt","w",stdout); #endif int test; cin >> test; while (test--) solve(); } ```
// 1543A.cpp // Created by Ashish Negi /******** All Required Header Files ********/ #include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <functional> #include <numeric> #include <utility> #include <limits> #include <time.h> #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #include "bits/stdc++.h" #include <numeric> // contains inbuilt gcd(a, b) function // #include "ext/pb_ds/assoc_container.hpp" // #include "ext/pb_ds/tree_policy.hpp" using namespace std; /******* All Required define Pre-Processors and typedef Constants *******/ const string nl = "\n"; #define scd(t) scanf("%d",&t) #define scld(t) scanf("%ld",&t) #define sclld(t) scanf("%lld",&t) #define scc(t) scanf("%c",&t) #define scs(t) scanf("%s",t) #define scf(t) scanf("%f",&t) #define sclf(t) scanf("%lf",&t) #define inp(t) cin>>t #define inpp(t,u) cin>>t>>u #define inppp(t,u,v) cin>>t>>u>>v #define out(t) cout<<t<<nl #define outt(t,u) cout<<t<<" "<<u<<nl #define outtt(t,u,v) cout<<t<<" "<<u<<" "<<v<<nl #define outf(t, p) cout << fixed; cout << setprecision(p); out(t); #define mems(a, b) memset(a, (b), sizeof(a)) #define lpj(i, j, k) for (int i=j ; i<k ; i+=1) #define rlpj(i, j, k) for (int i=j ; i>=k ; i-=1) #define lp(i, j) lpj(i, 0, j) #define rlp(i, j) rlpj(i, j, 0) #define inpv(a,n) lp(i, n) inp(a[i]) #define inpvv(a,n) lp(i, n)lp(j, n) inp(a[i][j]); #define outv(a,n) lp(i, n) { if(i != 0 ){ cout << " ";} cout << a[i]; } cout<<nl; #define outvv(a,n) lp(i, n){ lp(j, n){ if(j != 0 ){ cout << " ";} cout << a[i][j]; } cout<<nl; } #define outy() out("YES") #define outn() out("NO") #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define each(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define CNT(a, x) count(all(a), x) #define mpr make_pair #define pbk push_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 // #define MOD 1000000007 #define read(type) readInt<type>() #define clk_start() time_req = clock(); #define clk_end() cout << "time taken to solve (in seconds) = "; outf((float)(clock() - time_req)/(float)CLOCKS_PER_SEC, 6); #define ROTL(a, i) rotate(a.begin(), a.begin() + i, a.end()) #define ROTR(a, i) rotate(a.begin(), a.begin() + a.size() - i, a.end()) const double pi = acos(-1.0); typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<unsigned long long int> vi64; typedef vector<string> vs; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef map<int, int> mpii; typedef set<int> seti; typedef multiset<int> mseti; typedef long int int32; typedef unsigned long int uint32; typedef long long int int64; typedef unsigned long long int uint64; /****** Template of some basic operations *****/ template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } /**********************************************/ /****** Template of Fast I/O Methods *********/ template <typename T> inline void write(T x) { int i = 20; char buf[21]; // buf[10] = 0; buf[20] = '\n'; do { buf[--i] = x % 10 + '0'; x /= 10; } while (x); do { putchar(buf[i]); } while (buf[i++] != '\n'); } template <typename T> inline T readInt() { T n = 0, s = 1; char p = getchar(); if (p == '-') s = -1; while ((p < '0' || p > '9') && p != EOF && p != '-') p = getchar(); if (p == '-') s = -1, p = getchar(); while (p >= '0' && p <= '9') { n = (n << 3) + (n << 1) + (p - '0'); p = getchar(); } return n * s; } /************************************/ /*/---------------------------RNG----------------------/*/ mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) { uniform_int_distribution<int64_t> generator(l, r); return generator(rng); } struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393 static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } template<typename L, typename R> size_t operator()(pair<L, R> const& Y) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM); } }; /*/-----------------------Modular Arithmetic---------------/*/ const int mod = 1e9 + 7; template<const int MOD> struct modular_int { int x; static vector<int> inverse_list ; const static int inverse_limit; const static bool is_prime; modular_int() { x = 0; } template<typename T> modular_int(const T z) { x = (z % MOD); if (x < 0) x += MOD; } modular_int(const modular_int<MOD>* z) { x = z->x; } modular_int(const modular_int<MOD>& z) { x = z.x; } modular_int operator - (const modular_int<MOD>& m) const { modular_int<MOD> U; U.x = x - m.x; if (U.x < 0) U.x += MOD; return U; } modular_int operator + (const modular_int<MOD>& m) const { modular_int<MOD> U; U.x = x + m.x; if (U.x >= MOD) U.x -= MOD; return U; } modular_int& operator -= (const modular_int<MOD>& m) { x -= m.x; if (x < 0) x += MOD; return *this; } modular_int& operator += (const modular_int<MOD>& m) { x += m.x; if (x >= MOD) x -= MOD; return *this; } modular_int operator * (const modular_int<MOD>& m) const { modular_int<MOD> U; U.x = (x * 1ull * m.x) % MOD; return U; } modular_int& operator *= (const modular_int<MOD>& m) { x = (x * 1ull * m.x) % MOD; return *this; } template<typename T> friend modular_int operator + (const T &l, const modular_int<MOD>& p) { return (modular_int<MOD>(l) + p); } template<typename T> friend modular_int operator - (const T &l, const modular_int<MOD>& p) { return (modular_int<MOD>(l) - p); } template<typename T> friend modular_int operator * (const T &l, const modular_int<MOD>& p) { return (modular_int<MOD>(l) * p); } template<typename T> friend modular_int operator / (const T &l, const modular_int<MOD>& p) { return (modular_int<MOD>(l) / p); } int value() const { return x; } modular_int operator ^ (const modular_int<MOD>& cpower) const { modular_int<MOD> ans; ans.x = 1; modular_int<MOD> curr(this); int power = cpower.x; if (curr.x <= 1) { if (power == 0) curr.x = 1; return curr; } while ( power > 0) { if (power & 1) { ans *= curr; } power >>= 1; if (power) curr *= curr; } return ans; } modular_int operator ^ (long long power) const { modular_int<MOD> ans; ans.x = 1; modular_int<MOD> curr(this); if (curr.x <= 1) { if (power == 0) curr.x = 1; return curr; } // Prime Mods if (power >= MOD && is_prime) { power %= (MOD - 1); } while ( power > 0) { if (power & 1) { ans *= curr; } power >>= 1; if (power) curr *= curr; } return ans; } modular_int operator ^ (int power) const { modular_int<MOD> ans; ans.x = 1; modular_int<MOD> curr(this); if (curr.x <= 1) { if (power == 0) curr.x = 1; return curr; } while ( power > 0) { if (power & 1) { ans *= curr; } power >>= 1; if (power) curr *= curr; } return ans; } template<typename T> modular_int& operator ^= (T power) { modular_int<MOD> res = (*this)^power; x = res.x; return *this; } template<typename T> modular_int pow(T x) { return (*this)^x; } pair<long long, long long> gcd(const int a, const int b) const { if (b == 0) return {1, 0}; pair<long long, long long> c = gcd(b , a % b); return { c.second , c.first - (a / b)*c.second}; } inline void init_inverse_list() const { vector<int>& dp = modular_int<MOD>::inverse_list; dp.resize(modular_int<MOD>::inverse_limit + 1); int n = modular_int<MOD>::inverse_limit; dp[0] = 1; if (n > 1) dp[1] = 1; for (int i = 2; i <= n; ++i) { dp[i] = (dp[MOD % i] * 1ull * (MOD - MOD / i)) % MOD; } } modular_int<MOD> get_inv() const { if (modular_int<MOD>::inverse_list.size() < modular_int<MOD>::inverse_limit + 1) init_inverse_list(); if (this->x <= modular_int<MOD>::inverse_limit) { return modular_int<MOD>::inverse_list[this->x]; } pair<long long, long long> G = gcd(this->x, MOD); return modular_int<MOD>(G.first); } modular_int<MOD> operator - () const { modular_int<MOD> v(0); v -= (*this); return v; } modular_int operator / (const modular_int<MOD>& m) const { modular_int<MOD> U(this); U *= m.get_inv(); return U; } modular_int& operator /= (const modular_int<MOD>& m) { (*this) *= m.get_inv(); return *this; } bool operator==(const modular_int<MOD>& m) const { return x == m.x; } bool operator < (const modular_int<MOD>& m) const { return x < m.x; } template<typename T> bool operator == (const T& m) const { return (*this) == (modular_int<MOD>(m)); } template<typename T> bool operator < (const T& m) const { return x < (modular_int<MOD>(m)).x; } template<typename T> bool operator > (const T& m) const { return x > (modular_int<MOD>(m)).x; } template<typename T> friend bool operator == (const T& x, const modular_int<MOD>& m) { return (modular_int<MOD>(x)).x == m.x; } template<typename T> friend bool operator < (const T& x, const modular_int<MOD>& m) { return (modular_int<MOD>(x)).x < m.x; } template<typename T> friend bool operator > (const T& x, const modular_int<MOD>& m) { return (modular_int<MOD>(x)).x > m.x; } friend istream& operator >> (istream& is, modular_int<MOD>& p) { int64_t val; is >> val; p.x = (val % MOD); if (p.x < 0) p.x += MOD; return is; } friend ostream& operator << (ostream& os, const modular_int<MOD>& p) {return os << p.x;} }; using mint = modular_int<mod>; template<const int MOD> vector<int> modular_int<MOD>::inverse_list ; template<const int MOD> const int modular_int<MOD>::inverse_limit = -1; template<const int MOD> const bool modular_int<MOD>::is_prime = true; template<> //-> useful if computing inverse fact = i_f[i-1] / i; const int modular_int<mod>::inverse_limit = 1000; /******* Debugging Class Template *******/ #ifdef DEBUG #define debug(args...) (Debugger()) , args #define dbg(var1) cerr<<#var1<<" = "<<(var1)<<nl; #define dbg2(var1,var2) cerr<<#var1<<" = "<<(var1)<<", "<<#var2<<" = "<<(var2)<<nl; #define dbg3(var1,var2,var3) cerr<<#var1<<" = "<<(var1)<<", "<<#var2<<" = "<<(var2)<<", "<<#var3<<" = "<<(var3)<<nl; #define dbg4(var1,var2,var3,var4) cerr<<#var1<<" = "<<(var1)<<", "<<#var2<<" = "<<(var2)<<", "<<#var3<<" = "<<(var3)<<", "<<#var4<<" = "<<(var4)<<nl; class Debugger { public: Debugger(const std::string& _separator = " - ") : first(true), separator(_separator) {} template<typename ObjectType> Debugger& operator , (const ObjectType& v) { if (!first) std: cerr << separator; std::cerr << v; first = false; return *this; } ~Debugger() { std: cerr << nl;} private: bool first; std::string separator; }; #else #define debug(args...) // Just strip off all debug tokens #define dbg(args...) // Just strip off all debug tokens #define dbg2(args...) // Just strip off all debug tokens #define dbg3(args...) // Just strip off all debug tokens #define dbg4(args...) // Just strip off all debug tokens #endif /************** Macros ****************/ #ifndef ONLINE_JUDGE #define ONLINE_JUDGE #endif /* ONLINE_JUDGE */ // #define SUBLIME_TEXT // #define DEBUG // #define CLOCK #define MULT_TC /** Conditional variables/ constants **/ #ifdef CLOCK clock_t time_req; #endif /* CLOCK */ /***** Global variables/constants *****/ const int NMAX = 3e5; uint64 n, m; /******* User-defined Functions *******/ /**************************************/ void solve() { inpp(n, m); if (n == m) { outt(0, 0); return; } if (n > m) { swap(n, m); } uint64 diff = m - n; if (diff == n) { outt(diff, 0); } // else if (n < diff) { // if (diff - n > n) { // outt(diff, n); // } // else { // outt(diff, diff - n); // } // } else { outt(diff, min(n % diff, diff - (n % diff))); } return; } /********** Main() function **********/ int main() { #if !defined(ONLINE_JUDGE) || defined(SUBLIME_TEXT) freopen("../IO/input.txt", "r", stdin); freopen("../IO/output.txt", "w", stdout); freopen("../IO/log.txt", "w", stderr); #endif std::ios::sync_with_stdio(false); cin.tie(0); #ifdef MULT_TC int tc; inp(tc); while (tc--) { #endif /* MULT_TC */ #ifdef CLOCK clk_start(); #endif /* CLOCK */ solve(); #ifdef CLOCK clk_end(); #endif /* CLOCK */ #ifdef MULT_TC } #endif /* MULT_TC */ return 0; } /******** Main() Ends Here *************/
### Prompt Construct a cpp code solution to the problem outlined: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp // 1543A.cpp // Created by Ashish Negi /******** All Required Header Files ********/ #include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <functional> #include <numeric> #include <utility> #include <limits> #include <time.h> #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #include "bits/stdc++.h" #include <numeric> // contains inbuilt gcd(a, b) function // #include "ext/pb_ds/assoc_container.hpp" // #include "ext/pb_ds/tree_policy.hpp" using namespace std; /******* All Required define Pre-Processors and typedef Constants *******/ const string nl = "\n"; #define scd(t) scanf("%d",&t) #define scld(t) scanf("%ld",&t) #define sclld(t) scanf("%lld",&t) #define scc(t) scanf("%c",&t) #define scs(t) scanf("%s",t) #define scf(t) scanf("%f",&t) #define sclf(t) scanf("%lf",&t) #define inp(t) cin>>t #define inpp(t,u) cin>>t>>u #define inppp(t,u,v) cin>>t>>u>>v #define out(t) cout<<t<<nl #define outt(t,u) cout<<t<<" "<<u<<nl #define outtt(t,u,v) cout<<t<<" "<<u<<" "<<v<<nl #define outf(t, p) cout << fixed; cout << setprecision(p); out(t); #define mems(a, b) memset(a, (b), sizeof(a)) #define lpj(i, j, k) for (int i=j ; i<k ; i+=1) #define rlpj(i, j, k) for (int i=j ; i>=k ; i-=1) #define lp(i, j) lpj(i, 0, j) #define rlp(i, j) rlpj(i, j, 0) #define inpv(a,n) lp(i, n) inp(a[i]) #define inpvv(a,n) lp(i, n)lp(j, n) inp(a[i][j]); #define outv(a,n) lp(i, n) { if(i != 0 ){ cout << " ";} cout << a[i]; } cout<<nl; #define outvv(a,n) lp(i, n){ lp(j, n){ if(j != 0 ){ cout << " ";} cout << a[i][j]; } cout<<nl; } #define outy() out("YES") #define outn() out("NO") #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define each(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define CNT(a, x) count(all(a), x) #define mpr make_pair #define pbk push_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 // #define MOD 1000000007 #define read(type) readInt<type>() #define clk_start() time_req = clock(); #define clk_end() cout << "time taken to solve (in seconds) = "; outf((float)(clock() - time_req)/(float)CLOCKS_PER_SEC, 6); #define ROTL(a, i) rotate(a.begin(), a.begin() + i, a.end()) #define ROTR(a, i) rotate(a.begin(), a.begin() + a.size() - i, a.end()) const double pi = acos(-1.0); typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<unsigned long long int> vi64; typedef vector<string> vs; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef map<int, int> mpii; typedef set<int> seti; typedef multiset<int> mseti; typedef long int int32; typedef unsigned long int uint32; typedef long long int int64; typedef unsigned long long int uint64; /****** Template of some basic operations *****/ template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } /**********************************************/ /****** Template of Fast I/O Methods *********/ template <typename T> inline void write(T x) { int i = 20; char buf[21]; // buf[10] = 0; buf[20] = '\n'; do { buf[--i] = x % 10 + '0'; x /= 10; } while (x); do { putchar(buf[i]); } while (buf[i++] != '\n'); } template <typename T> inline T readInt() { T n = 0, s = 1; char p = getchar(); if (p == '-') s = -1; while ((p < '0' || p > '9') && p != EOF && p != '-') p = getchar(); if (p == '-') s = -1, p = getchar(); while (p >= '0' && p <= '9') { n = (n << 3) + (n << 1) + (p - '0'); p = getchar(); } return n * s; } /************************************/ /*/---------------------------RNG----------------------/*/ mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) { uniform_int_distribution<int64_t> generator(l, r); return generator(rng); } struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393 static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } template<typename L, typename R> size_t operator()(pair<L, R> const& Y) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM); } }; /*/-----------------------Modular Arithmetic---------------/*/ const int mod = 1e9 + 7; template<const int MOD> struct modular_int { int x; static vector<int> inverse_list ; const static int inverse_limit; const static bool is_prime; modular_int() { x = 0; } template<typename T> modular_int(const T z) { x = (z % MOD); if (x < 0) x += MOD; } modular_int(const modular_int<MOD>* z) { x = z->x; } modular_int(const modular_int<MOD>& z) { x = z.x; } modular_int operator - (const modular_int<MOD>& m) const { modular_int<MOD> U; U.x = x - m.x; if (U.x < 0) U.x += MOD; return U; } modular_int operator + (const modular_int<MOD>& m) const { modular_int<MOD> U; U.x = x + m.x; if (U.x >= MOD) U.x -= MOD; return U; } modular_int& operator -= (const modular_int<MOD>& m) { x -= m.x; if (x < 0) x += MOD; return *this; } modular_int& operator += (const modular_int<MOD>& m) { x += m.x; if (x >= MOD) x -= MOD; return *this; } modular_int operator * (const modular_int<MOD>& m) const { modular_int<MOD> U; U.x = (x * 1ull * m.x) % MOD; return U; } modular_int& operator *= (const modular_int<MOD>& m) { x = (x * 1ull * m.x) % MOD; return *this; } template<typename T> friend modular_int operator + (const T &l, const modular_int<MOD>& p) { return (modular_int<MOD>(l) + p); } template<typename T> friend modular_int operator - (const T &l, const modular_int<MOD>& p) { return (modular_int<MOD>(l) - p); } template<typename T> friend modular_int operator * (const T &l, const modular_int<MOD>& p) { return (modular_int<MOD>(l) * p); } template<typename T> friend modular_int operator / (const T &l, const modular_int<MOD>& p) { return (modular_int<MOD>(l) / p); } int value() const { return x; } modular_int operator ^ (const modular_int<MOD>& cpower) const { modular_int<MOD> ans; ans.x = 1; modular_int<MOD> curr(this); int power = cpower.x; if (curr.x <= 1) { if (power == 0) curr.x = 1; return curr; } while ( power > 0) { if (power & 1) { ans *= curr; } power >>= 1; if (power) curr *= curr; } return ans; } modular_int operator ^ (long long power) const { modular_int<MOD> ans; ans.x = 1; modular_int<MOD> curr(this); if (curr.x <= 1) { if (power == 0) curr.x = 1; return curr; } // Prime Mods if (power >= MOD && is_prime) { power %= (MOD - 1); } while ( power > 0) { if (power & 1) { ans *= curr; } power >>= 1; if (power) curr *= curr; } return ans; } modular_int operator ^ (int power) const { modular_int<MOD> ans; ans.x = 1; modular_int<MOD> curr(this); if (curr.x <= 1) { if (power == 0) curr.x = 1; return curr; } while ( power > 0) { if (power & 1) { ans *= curr; } power >>= 1; if (power) curr *= curr; } return ans; } template<typename T> modular_int& operator ^= (T power) { modular_int<MOD> res = (*this)^power; x = res.x; return *this; } template<typename T> modular_int pow(T x) { return (*this)^x; } pair<long long, long long> gcd(const int a, const int b) const { if (b == 0) return {1, 0}; pair<long long, long long> c = gcd(b , a % b); return { c.second , c.first - (a / b)*c.second}; } inline void init_inverse_list() const { vector<int>& dp = modular_int<MOD>::inverse_list; dp.resize(modular_int<MOD>::inverse_limit + 1); int n = modular_int<MOD>::inverse_limit; dp[0] = 1; if (n > 1) dp[1] = 1; for (int i = 2; i <= n; ++i) { dp[i] = (dp[MOD % i] * 1ull * (MOD - MOD / i)) % MOD; } } modular_int<MOD> get_inv() const { if (modular_int<MOD>::inverse_list.size() < modular_int<MOD>::inverse_limit + 1) init_inverse_list(); if (this->x <= modular_int<MOD>::inverse_limit) { return modular_int<MOD>::inverse_list[this->x]; } pair<long long, long long> G = gcd(this->x, MOD); return modular_int<MOD>(G.first); } modular_int<MOD> operator - () const { modular_int<MOD> v(0); v -= (*this); return v; } modular_int operator / (const modular_int<MOD>& m) const { modular_int<MOD> U(this); U *= m.get_inv(); return U; } modular_int& operator /= (const modular_int<MOD>& m) { (*this) *= m.get_inv(); return *this; } bool operator==(const modular_int<MOD>& m) const { return x == m.x; } bool operator < (const modular_int<MOD>& m) const { return x < m.x; } template<typename T> bool operator == (const T& m) const { return (*this) == (modular_int<MOD>(m)); } template<typename T> bool operator < (const T& m) const { return x < (modular_int<MOD>(m)).x; } template<typename T> bool operator > (const T& m) const { return x > (modular_int<MOD>(m)).x; } template<typename T> friend bool operator == (const T& x, const modular_int<MOD>& m) { return (modular_int<MOD>(x)).x == m.x; } template<typename T> friend bool operator < (const T& x, const modular_int<MOD>& m) { return (modular_int<MOD>(x)).x < m.x; } template<typename T> friend bool operator > (const T& x, const modular_int<MOD>& m) { return (modular_int<MOD>(x)).x > m.x; } friend istream& operator >> (istream& is, modular_int<MOD>& p) { int64_t val; is >> val; p.x = (val % MOD); if (p.x < 0) p.x += MOD; return is; } friend ostream& operator << (ostream& os, const modular_int<MOD>& p) {return os << p.x;} }; using mint = modular_int<mod>; template<const int MOD> vector<int> modular_int<MOD>::inverse_list ; template<const int MOD> const int modular_int<MOD>::inverse_limit = -1; template<const int MOD> const bool modular_int<MOD>::is_prime = true; template<> //-> useful if computing inverse fact = i_f[i-1] / i; const int modular_int<mod>::inverse_limit = 1000; /******* Debugging Class Template *******/ #ifdef DEBUG #define debug(args...) (Debugger()) , args #define dbg(var1) cerr<<#var1<<" = "<<(var1)<<nl; #define dbg2(var1,var2) cerr<<#var1<<" = "<<(var1)<<", "<<#var2<<" = "<<(var2)<<nl; #define dbg3(var1,var2,var3) cerr<<#var1<<" = "<<(var1)<<", "<<#var2<<" = "<<(var2)<<", "<<#var3<<" = "<<(var3)<<nl; #define dbg4(var1,var2,var3,var4) cerr<<#var1<<" = "<<(var1)<<", "<<#var2<<" = "<<(var2)<<", "<<#var3<<" = "<<(var3)<<", "<<#var4<<" = "<<(var4)<<nl; class Debugger { public: Debugger(const std::string& _separator = " - ") : first(true), separator(_separator) {} template<typename ObjectType> Debugger& operator , (const ObjectType& v) { if (!first) std: cerr << separator; std::cerr << v; first = false; return *this; } ~Debugger() { std: cerr << nl;} private: bool first; std::string separator; }; #else #define debug(args...) // Just strip off all debug tokens #define dbg(args...) // Just strip off all debug tokens #define dbg2(args...) // Just strip off all debug tokens #define dbg3(args...) // Just strip off all debug tokens #define dbg4(args...) // Just strip off all debug tokens #endif /************** Macros ****************/ #ifndef ONLINE_JUDGE #define ONLINE_JUDGE #endif /* ONLINE_JUDGE */ // #define SUBLIME_TEXT // #define DEBUG // #define CLOCK #define MULT_TC /** Conditional variables/ constants **/ #ifdef CLOCK clock_t time_req; #endif /* CLOCK */ /***** Global variables/constants *****/ const int NMAX = 3e5; uint64 n, m; /******* User-defined Functions *******/ /**************************************/ void solve() { inpp(n, m); if (n == m) { outt(0, 0); return; } if (n > m) { swap(n, m); } uint64 diff = m - n; if (diff == n) { outt(diff, 0); } // else if (n < diff) { // if (diff - n > n) { // outt(diff, n); // } // else { // outt(diff, diff - n); // } // } else { outt(diff, min(n % diff, diff - (n % diff))); } return; } /********** Main() function **********/ int main() { #if !defined(ONLINE_JUDGE) || defined(SUBLIME_TEXT) freopen("../IO/input.txt", "r", stdin); freopen("../IO/output.txt", "w", stdout); freopen("../IO/log.txt", "w", stderr); #endif std::ios::sync_with_stdio(false); cin.tie(0); #ifdef MULT_TC int tc; inp(tc); while (tc--) { #endif /* MULT_TC */ #ifdef CLOCK clk_start(); #endif /* CLOCK */ solve(); #ifdef CLOCK clk_end(); #endif /* CLOCK */ #ifdef MULT_TC } #endif /* MULT_TC */ return 0; } /******** Main() Ends Here *************/ ```
#include<bits/stdc++.h> #define ll long long #define all( x ) x.begin() , x.end() using namespace std ; void solve() { // If there is only one test case make t = 1 ll a , b ; cin >> a >> b ; ll req = abs( a - b ) ; ll moves = 1e18 ; if( req ) { ll x = min( a , b ) % req ; if( req - x > 0 ) moves = x ; moves = min( moves , req - x ) ; } else moves = 0 ; cout << req << " " << moves << endl ; } int main() { ios_base :: sync_with_stdio( false ) ; cin.tie( NULL ) ; int t ; cin >> t ; while( t-- ) solve() ; }
### Prompt Your task is to create a cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> #define ll long long #define all( x ) x.begin() , x.end() using namespace std ; void solve() { // If there is only one test case make t = 1 ll a , b ; cin >> a >> b ; ll req = abs( a - b ) ; ll moves = 1e18 ; if( req ) { ll x = min( a , b ) % req ; if( req - x > 0 ) moves = x ; moves = min( moves , req - x ) ; } else moves = 0 ; cout << req << " " << moves << endl ; } int main() { ios_base :: sync_with_stdio( false ) ; cin.tie( NULL ) ; int t ; cin >> t ; while( t-- ) solve() ; } ```
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { #ifndef ONLINE_JUDGE //input from input.txt freopen("input.txt", "r", stdin); //output on output.txt freopen("output.txt", "w", stdout); #endif ll tc; cin>>tc; for(int i=0;i<tc;i++) { ll a,b; cin>>a>>b; ll temp=abs(b-a); if(a==b) { cout<<0<<" "<<0<<endl; continue; } else { ll sel=max(a,b); ll low=sel/temp; ll high=((low+1)*temp)-sel; cout<<temp<<" "<<min(sel%temp,high)<<endl; } } return 0; }
### Prompt Construct a cpp code solution to the problem outlined: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> #define ll long long using namespace std; int main() { #ifndef ONLINE_JUDGE //input from input.txt freopen("input.txt", "r", stdin); //output on output.txt freopen("output.txt", "w", stdout); #endif ll tc; cin>>tc; for(int i=0;i<tc;i++) { ll a,b; cin>>a>>b; ll temp=abs(b-a); if(a==b) { cout<<0<<" "<<0<<endl; continue; } else { ll sel=max(a,b); ll low=sel/temp; ll high=((low+1)*temp)-sel; cout<<temp<<" "<<min(sel%temp,high)<<endl; } } return 0; } ```
#include<bits/stdc++.h> #define ll long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr) ,cout.tie(nullptr); const int mod = 1000000007; using namespace std; void solve(){ ll a,b; cin>>a>>b; if(a==b){ cout<<0<<" "<<0<<endl; return ; } if(a>b) swap(a,b); ll gcd = abs(b-a); ll k = a%gcd; ll p= gcd-k; cout<<gcd<<" "<<min(k,p)<<endl; } int main(){ fast ll t; cin>>t; while(t--){ solve(); } return 0; }
### Prompt Your challenge is to write a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> #define ll long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr) ,cout.tie(nullptr); const int mod = 1000000007; using namespace std; void solve(){ ll a,b; cin>>a>>b; if(a==b){ cout<<0<<" "<<0<<endl; return ; } if(a>b) swap(a,b); ll gcd = abs(b-a); ll k = a%gcd; ll p= gcd-k; cout<<gcd<<" "<<min(k,p)<<endl; } int main(){ fast ll t; cin>>t; while(t--){ solve(); } return 0; } ```
#include<bits/stdc++.h> using namespace std; #define int long long void solve(){ int a,b; cin>>a>>b; if(a==b){ cout<<0<<' '<<0<<'\n'; return; } if(b<a)swap(a,b); set<int>facts; int diff=b-a; int ans=diff; int moves=b/diff; if(b%ans==0){ cout<<ans<<" "<<0<<'\n'; return; }else{ cout<<ans<<" "<<min(b%diff,llabs(b-diff*(moves+1)))<<'\n'; } } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); int tt; cin>>tt; while(tt--){ solve(); } return 0; }
### Prompt Create a solution in cpp for the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define int long long void solve(){ int a,b; cin>>a>>b; if(a==b){ cout<<0<<' '<<0<<'\n'; return; } if(b<a)swap(a,b); set<int>facts; int diff=b-a; int ans=diff; int moves=b/diff; if(b%ans==0){ cout<<ans<<" "<<0<<'\n'; return; }else{ cout<<ans<<" "<<min(b%diff,llabs(b-diff*(moves+1)))<<'\n'; } } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); int tt; cin>>tt; while(tt--){ solve(); } return 0; } ```
#include<bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" const double pi = acos(-1); #define pb push_back #define LL unsigned long long int static dp[1005][1005]; #define RADHE KRISHNA const int MOD = 1e9 + 7; const int N = 1e6 + 2; // int lcs(string s , string t , int n , int m){ // //base case // if(n == 0 || m == 0){ // return 0; // } // if(dp[n][m] != -1){ // return dp[n][m]; // } // if(s[n-1] == t[m - 1]){ // return (dp[n][m] = 1 + lcs(s , t , n - 1 , m - 1)); // } // else{ // return dp[n][m] = max(lcs(s ,t ,n-1 ,m) ,lcs(s ,t ,n ,m - 1) ); // } // } // ll Pow(ll n, ll p, ll m) { // if(!p) return 1; // else if(p & 1) return (n * Pow(n, p-1, m)) % m; // else { // ll v = Pow(n, p/2, m); // return (v*v) % m; // } // } // bool isprime(ll n){ // if(n<2) return false; // for(ll i=2;i*i*i<=n;++i) if(n%i==0) return false; // for(int it=0;it<1e5;++it){ // ll i = rand()%(n-1)+1; // if(__gcd(i,n)!=1) return false; // if(Pow(i,n-1,n)!=1) return false; // } // return true; // } // void check(ll q){ // vector<int>v; // for(int i = 2 ; i*i <= q; i++){ // if(q % i == 0){ // v.push_back(i); // if(i != q/i){ // v.push_back(q/i); // } // } // } // for(auto x : v){ // cout<<x<<" "; // } // } // set<int>s; // void SieveOfEratosthenes(ll n) // { // bool prime[n + 2]; // memset(prime, true, sizeof(prime)); // for (int p = 2; p * p <= n+1; p++) // { // if (prime[p] == true) // { // for (ll i = p * p; i <= n+1; i += p) // prime[i] = false; // } // } // for (ll p = 2; p <= n+1; p++){ // if (prime[p]){ // s.insert(p); // } // } // } // bool check(int x){ // int y = sqrt(x); // return y*y == x; // } //ll fac[200002]; // bool rev(int i){ // return (s[i] == t[s.size() - i - 1] && s[s.size() - i - 1] == t[i]); // } //queue<pair<pair<int ,int>, int>>q; // bool valid(int x ,int y){ // if(x > 0 && x <= n && y > 0 && y <= m){ // return true; // } // else{ // false; // } // } // bool checkk(int x ,int y){ // return x >= 0 && x < n && y >= 0 && y < m; // } //vector<int>adj[200001]; //ll vis[200001]; //bool is_cycle; //ll min_cost; //int dx1[] = {1,1,1,-1,-1,-1,0,0}; //int dy1[] = {1,0,-1, 1, 0, -1, 1, -1}; // int dx[4]={-1,0,0,1}; // int dy[4]={0,1,-1,0}; // char a[101][101]; // bool vis[101][101]; // int n ,m; // bool valid(int x , int y){ // if(x < 0 || x >= n || y < 0 || y >= m || a[x][y] == '.' || vis[x][y]==true){ // return false; // } // else{ // return true; // } // } // void dfs(ll x ,ll y){ // vis[x][y] = true; // for(int i = 0 ; i < 4; i++){ // int new_x = x + dx[i]; // int new_y = y + dy[i]; // if(valid(new_x , new_y)){ // dfs(new_x , new_y); // } // } // } int prime[N+1]; vector<int>v; void seive(){ memset(prime , true , sizeof(prime)); prime[0] = false; prime[1] = false; for(int i = 2; i <= N; i++){ if(prime[i]){ v.push_back(i); for(int j = 2*i; j <= N; j += i){ prime[j] = false; } } } } //int score[12] = {15 , 12 , 10 ,9 ,8, 7, 6, 5, 4, 3 ,2 ,1}; void solve(){ // cin>>n>>m; // cin>>ch; // set<char>s; // int new_x , new_y; // char mat[n+1][m+1]; // for(int i = 0 ; i < n ;i++){ // for(int j = 0 ;j < m ;j++){ // cin>>mat[i][j]; // } // } // for(int i = 0; i < n; i++){ // for(int j = 0; j < m; j++) { // if(mat[i][j] == ch){ // for(int k = 0; k < 4; k++){ // new_x = i + dx[k]; // new_y = j + dy[k]; // if(checkk(new_x,new_y) && mat[new_x][new_y] != '.' && mat[new_x][new_y] != ch){ // s.insert(mat[new_x][new_y]); // } // } // } // } // } // cout<<s.size()<<endl; // int a[4]; // for(int i = 0 ; i < 4; i++){ // cin>>a[i]; // } // sort(a, a+4); // if(a[0] + a[1] > a[2] || a[1]+a[2] > a[3]){ // cout<<"TRIANGLE"<<endl; // } // else if(a[0] + a[1] >= a[2] || a[1] + a[2] >= a[3]){ // cout<<"SEGMENT"<<endl; // } // else{ // cout<<"IMPOSSIBLE"<<endl; // } // int n; // cin>>n; // for(int i = 1; i <= n; i++){ // vis[i] = 0; // } // for(int i = 1 ; i <= n ;i++){ // cin>>a[i]; // } // for(int i = 1 ; i <= n ;i++){ // cin>>b[i]; // p[a[i]] = b[i]; // } // int ans = 0; // for(int i = 1; i <= n; i++){ // // if(vis[i] || p[i] == i){ // // continue; // // } // if(!vis[i]){ // ans++; // int tmp = i; // while(!vis[tmp]){ // vis[tmp] = 1; // tmp = p[tmp]; // } // } // } // cout<<Pow(2 , ans , MOD)<<endl; // ll n ,m; // cin>>n>>m; // int ans = INT_MIN , num , cnt , tmp; // for(int i = n ; i <= m ; i++){ // tmp = i, cnt = 0; // while(tmp){ // if(tmp & 1){ // cnt++; // } // tmp >>= 1ll; // } // if(cnt > ans){ // ans = cnt; // num = i; // } // } // cout<<num<<endl; ll a,b; cin>>a>>b; if(a==b){ cout<<0<<" "<<0<<endl; } else if(a<b){ ll val=b-a; cout<<val<<" "<<min(a%val,val-a%val)<<endl; } else{ ll val=a-b; cout<<val<<" "<<min(b%val,val-b%val)<<endl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int t ; cin>>t; while(t--){ // int n ,m; // cin>>n>>m; // string s ,t; // cin>>s>>t; // memset(dp , -1 , sizeof(dp)); // cout<< n + m - lcs(s , t ,n ,m)<<endl; solve(); } }
### Prompt Construct a Cpp code solution to the problem outlined: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" const double pi = acos(-1); #define pb push_back #define LL unsigned long long int static dp[1005][1005]; #define RADHE KRISHNA const int MOD = 1e9 + 7; const int N = 1e6 + 2; // int lcs(string s , string t , int n , int m){ // //base case // if(n == 0 || m == 0){ // return 0; // } // if(dp[n][m] != -1){ // return dp[n][m]; // } // if(s[n-1] == t[m - 1]){ // return (dp[n][m] = 1 + lcs(s , t , n - 1 , m - 1)); // } // else{ // return dp[n][m] = max(lcs(s ,t ,n-1 ,m) ,lcs(s ,t ,n ,m - 1) ); // } // } // ll Pow(ll n, ll p, ll m) { // if(!p) return 1; // else if(p & 1) return (n * Pow(n, p-1, m)) % m; // else { // ll v = Pow(n, p/2, m); // return (v*v) % m; // } // } // bool isprime(ll n){ // if(n<2) return false; // for(ll i=2;i*i*i<=n;++i) if(n%i==0) return false; // for(int it=0;it<1e5;++it){ // ll i = rand()%(n-1)+1; // if(__gcd(i,n)!=1) return false; // if(Pow(i,n-1,n)!=1) return false; // } // return true; // } // void check(ll q){ // vector<int>v; // for(int i = 2 ; i*i <= q; i++){ // if(q % i == 0){ // v.push_back(i); // if(i != q/i){ // v.push_back(q/i); // } // } // } // for(auto x : v){ // cout<<x<<" "; // } // } // set<int>s; // void SieveOfEratosthenes(ll n) // { // bool prime[n + 2]; // memset(prime, true, sizeof(prime)); // for (int p = 2; p * p <= n+1; p++) // { // if (prime[p] == true) // { // for (ll i = p * p; i <= n+1; i += p) // prime[i] = false; // } // } // for (ll p = 2; p <= n+1; p++){ // if (prime[p]){ // s.insert(p); // } // } // } // bool check(int x){ // int y = sqrt(x); // return y*y == x; // } //ll fac[200002]; // bool rev(int i){ // return (s[i] == t[s.size() - i - 1] && s[s.size() - i - 1] == t[i]); // } //queue<pair<pair<int ,int>, int>>q; // bool valid(int x ,int y){ // if(x > 0 && x <= n && y > 0 && y <= m){ // return true; // } // else{ // false; // } // } // bool checkk(int x ,int y){ // return x >= 0 && x < n && y >= 0 && y < m; // } //vector<int>adj[200001]; //ll vis[200001]; //bool is_cycle; //ll min_cost; //int dx1[] = {1,1,1,-1,-1,-1,0,0}; //int dy1[] = {1,0,-1, 1, 0, -1, 1, -1}; // int dx[4]={-1,0,0,1}; // int dy[4]={0,1,-1,0}; // char a[101][101]; // bool vis[101][101]; // int n ,m; // bool valid(int x , int y){ // if(x < 0 || x >= n || y < 0 || y >= m || a[x][y] == '.' || vis[x][y]==true){ // return false; // } // else{ // return true; // } // } // void dfs(ll x ,ll y){ // vis[x][y] = true; // for(int i = 0 ; i < 4; i++){ // int new_x = x + dx[i]; // int new_y = y + dy[i]; // if(valid(new_x , new_y)){ // dfs(new_x , new_y); // } // } // } int prime[N+1]; vector<int>v; void seive(){ memset(prime , true , sizeof(prime)); prime[0] = false; prime[1] = false; for(int i = 2; i <= N; i++){ if(prime[i]){ v.push_back(i); for(int j = 2*i; j <= N; j += i){ prime[j] = false; } } } } //int score[12] = {15 , 12 , 10 ,9 ,8, 7, 6, 5, 4, 3 ,2 ,1}; void solve(){ // cin>>n>>m; // cin>>ch; // set<char>s; // int new_x , new_y; // char mat[n+1][m+1]; // for(int i = 0 ; i < n ;i++){ // for(int j = 0 ;j < m ;j++){ // cin>>mat[i][j]; // } // } // for(int i = 0; i < n; i++){ // for(int j = 0; j < m; j++) { // if(mat[i][j] == ch){ // for(int k = 0; k < 4; k++){ // new_x = i + dx[k]; // new_y = j + dy[k]; // if(checkk(new_x,new_y) && mat[new_x][new_y] != '.' && mat[new_x][new_y] != ch){ // s.insert(mat[new_x][new_y]); // } // } // } // } // } // cout<<s.size()<<endl; // int a[4]; // for(int i = 0 ; i < 4; i++){ // cin>>a[i]; // } // sort(a, a+4); // if(a[0] + a[1] > a[2] || a[1]+a[2] > a[3]){ // cout<<"TRIANGLE"<<endl; // } // else if(a[0] + a[1] >= a[2] || a[1] + a[2] >= a[3]){ // cout<<"SEGMENT"<<endl; // } // else{ // cout<<"IMPOSSIBLE"<<endl; // } // int n; // cin>>n; // for(int i = 1; i <= n; i++){ // vis[i] = 0; // } // for(int i = 1 ; i <= n ;i++){ // cin>>a[i]; // } // for(int i = 1 ; i <= n ;i++){ // cin>>b[i]; // p[a[i]] = b[i]; // } // int ans = 0; // for(int i = 1; i <= n; i++){ // // if(vis[i] || p[i] == i){ // // continue; // // } // if(!vis[i]){ // ans++; // int tmp = i; // while(!vis[tmp]){ // vis[tmp] = 1; // tmp = p[tmp]; // } // } // } // cout<<Pow(2 , ans , MOD)<<endl; // ll n ,m; // cin>>n>>m; // int ans = INT_MIN , num , cnt , tmp; // for(int i = n ; i <= m ; i++){ // tmp = i, cnt = 0; // while(tmp){ // if(tmp & 1){ // cnt++; // } // tmp >>= 1ll; // } // if(cnt > ans){ // ans = cnt; // num = i; // } // } // cout<<num<<endl; ll a,b; cin>>a>>b; if(a==b){ cout<<0<<" "<<0<<endl; } else if(a<b){ ll val=b-a; cout<<val<<" "<<min(a%val,val-a%val)<<endl; } else{ ll val=a-b; cout<<val<<" "<<min(b%val,val-b%val)<<endl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int t ; cin>>t; while(t--){ // int n ,m; // cin>>n>>m; // string s ,t; // cin>>s>>t; // memset(dp , -1 , sizeof(dp)); // cout<< n + m - lcs(s , t ,n ,m)<<endl; solve(); } } ```
#include<bits/stdc++.h> using namespace std; #define int int64_t void solve(){ int a,b; cin >> a >> b; if(a == b){ cout << "0 0\n"; return; } if(a > b) swap(a,b); int ans = b - a; if(ans == a) cout << ans << " " << 0 << '\n'; else{ cout << ans << " " << min(a%ans,ans-a%ans) << '\n'; } } signed main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); int t=1; cin>>t; while(t--){ solve(); } }
### Prompt In cpp, your task is to solve the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define int int64_t void solve(){ int a,b; cin >> a >> b; if(a == b){ cout << "0 0\n"; return; } if(a > b) swap(a,b); int ans = b - a; if(ans == a) cout << ans << " " << 0 << '\n'; else{ cout << ans << " " << min(a%ans,ans-a%ans) << '\n'; } } signed main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); int t=1; cin>>t; while(t--){ solve(); } } ```
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; while(t--){ long long a, b; cin >> a >> b; long long maxx, minn; maxx = max(a, b); minn = min(a, b); cout << maxx - minn << " "; if(a == b){ cout << 0 << endl; } else { cout << min(minn % (maxx-minn), maxx - minn - minn % (maxx-minn)) << endl; } } }
### Prompt Your task is to create a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; while(t--){ long long a, b; cin >> a >> b; long long maxx, minn; maxx = max(a, b); minn = min(a, b); cout << maxx - minn << " "; if(a == b){ cout << 0 << endl; } else { cout << min(minn % (maxx-minn), maxx - minn - minn % (maxx-minn)) << endl; } } } ```
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ll t; cin>>t; while(t--) { ll a,b; cin>>a>>b; if(a==b) cout<<0<<" "<<0<<endl; else { ll gcd = abs(b-a); ll minn = min(a%gcd,gcd-a%gcd); cout<<gcd<<" "<<minn<<endl; } } return 0; }
### Prompt Generate a cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ll t; cin>>t; while(t--) { ll a,b; cin>>a>>b; if(a==b) cout<<0<<" "<<0<<endl; else { ll gcd = abs(b-a); ll minn = min(a%gcd,gcd-a%gcd); cout<<gcd<<" "<<minn<<endl; } } return 0; } ```
#include <bits/stdc++.h> #define ll long long int #define st string #define pb(x) push_back(x) #define sz size() using namespace std; const ll maxn=1e3*2+1,maxv=1e6,mod=1e9; ll a1[maxn]; ll dp[maxn]; int main() { std::ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0); ll n,a,b; cin>>n; for(int i=1;i<=n;i++){ cin>>a>>b; ll c=abs(a-b); if(c==0) cout<<0<<" "<<0<<endl; else cout<<c<<" "<<min((a%c),c-(a%c))<<endl; } }
### Prompt Please formulate a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> #define ll long long int #define st string #define pb(x) push_back(x) #define sz size() using namespace std; const ll maxn=1e3*2+1,maxv=1e6,mod=1e9; ll a1[maxn]; ll dp[maxn]; int main() { std::ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0); ll n,a,b; cin>>n; for(int i=1;i<=n;i++){ cin>>a>>b; ll c=abs(a-b); if(c==0) cout<<0<<" "<<0<<endl; else cout<<c<<" "<<min((a%c),c-(a%c))<<endl; } } ```
#include <iostream> using namespace std; #define f(x,y,z) for(int x=y;x<z;++x) typedef long long ll; ll a, b, s, t; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); for(cin >> t; t--;) { cin >> a >> b; s = abs(a-b); cout << s << ' '; if(s < 2) cout << "0\n"; else { a = min(a, b); cout << min(a%s, s-a%s) << '\n'; } } }
### Prompt Please provide a Cpp coded solution to the problem described below: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <iostream> using namespace std; #define f(x,y,z) for(int x=y;x<z;++x) typedef long long ll; ll a, b, s, t; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); for(cin >> t; t--;) { cin >> a >> b; s = abs(a-b); cout << s << ' '; if(s < 2) cout << "0\n"; else { a = min(a, b); cout << min(a%s, s-a%s) << '\n'; } } } ```
#include <bits/stdc++.h> using namespace std; long long add(vector<long long> v,int n){ long long ans = 0; for(long long x: v){ ans+=x; ans = ans%n; } return ans; } void solve() { long long a,b; cin >> a >> b; if(b>a){ long long t = a; a = b; b = t; } cout << (a-b) << " " << ((a-b != 0)?min((b)%(a-b), (a-b) - b%(a-b)):0) <<endl; } int main() { long long t; cin >> t; while (t--) { solve(); } }
### Prompt Generate a cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; long long add(vector<long long> v,int n){ long long ans = 0; for(long long x: v){ ans+=x; ans = ans%n; } return ans; } void solve() { long long a,b; cin >> a >> b; if(b>a){ long long t = a; a = b; b = t; } cout << (a-b) << " " << ((a-b != 0)?min((b)%(a-b), (a-b) - b%(a-b)):0) <<endl; } int main() { long long t; cin >> t; while (t--) { solve(); } } ```
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i,n) for(int i=0;i<n;i++) #define endl ("\n") #define pb push_back #define mp make_pair #define pl pair<ll, ll> #define vl vector<ll> #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL); #define M 1000000007 const int N=2e5+2; ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);} ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);} vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m int fact[N]; void precalc(){ fact[0]=1; for(int i=1;i<N;i++){ fact[i]=mod_mul(fact[i-1],i,M); } } long long mod(long long x){ return ((x%M + M)%M); } ll inv(ll x){ return expo(x,M-2,M); } ll divide(ll a, ll b){ return mod_mul(a,inv(b),M); } ll nCr(ll n, ll r){ return divide(fact[n],mod_mul(fact[r],fact[n-r],M)); } int main() { fastIO ll t; cin>>t; while(t--){ ll a,b; cin>>a>>b; ll d=abs(a-b); ll e=max(a,b); if(a==b){ cout<<0<<" "<<0<<endl; continue; } ll k=e%d; ll v; if(d-k>=0 and d-k<k) v=d-k; else v=k; cout<<d<<" "<<v<<endl; } }
### Prompt Please formulate a cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; #define ll long long #define f(i,n) for(int i=0;i<n;i++) #define endl ("\n") #define pb push_back #define mp make_pair #define pl pair<ll, ll> #define vl vector<ll> #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL); #define M 1000000007 const int N=2e5+2; ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);} ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);} vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m int fact[N]; void precalc(){ fact[0]=1; for(int i=1;i<N;i++){ fact[i]=mod_mul(fact[i-1],i,M); } } long long mod(long long x){ return ((x%M + M)%M); } ll inv(ll x){ return expo(x,M-2,M); } ll divide(ll a, ll b){ return mod_mul(a,inv(b),M); } ll nCr(ll n, ll r){ return divide(fact[n],mod_mul(fact[r],fact[n-r],M)); } int main() { fastIO ll t; cin>>t; while(t--){ ll a,b; cin>>a>>b; ll d=abs(a-b); ll e=max(a,b); if(a==b){ cout<<0<<" "<<0<<endl; continue; } ll k=e%d; ll v; if(d-k>=0 and d-k<k) v=d-k; else v=k; cout<<d<<" "<<v<<endl; } } ```
#include <bits/stdc++.h> typedef long long int ll; const unsigned int MOD = 1000000007; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; cin >> t; for (int tt = 0; tt < t; tt++) { ll a,b; cin>>a>>b; if(a>b) swap(a,b); if(a==b) cout<<"0 0\n"; else { ll x=abs(a-b); ll y= a%x; y = min(y, x-y); cout<<x<<" "<<y<<"\n"; } } #ifndef ONLINE_JUDGE cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; #endif return 0; }
### Prompt Construct a CPP code solution to the problem outlined: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> typedef long long int ll; const unsigned int MOD = 1000000007; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; cin >> t; for (int tt = 0; tt < t; tt++) { ll a,b; cin>>a>>b; if(a>b) swap(a,b); if(a==b) cout<<"0 0\n"; else { ll x=abs(a-b); ll y= a%x; y = min(y, x-y); cout<<x<<" "<<y<<"\n"; } } #ifndef ONLINE_JUDGE cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; #endif return 0; } ```
#include <bits/stdc++.h> using namespace std; void excbet() { long long a, b; cin >> a >> b; long long c = abs(a - b); long long d = 0; if( c != 0) d = a%c; cout << c << " " << min(d, c-d) << endl; } int main() { int t; cin >> t; for(int i=0; i<t; i++) { excbet(); } return 0; }
### Prompt Generate a CPP solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; void excbet() { long long a, b; cin >> a >> b; long long c = abs(a - b); long long d = 0; if( c != 0) d = a%c; cout << c << " " << min(d, c-d) << endl; } int main() { int t; cin >> t; for(int i=0; i<t; i++) { excbet(); } return 0; } ```
#include<bits/stdc++.h> using namespace std; #define ll long long ll const MAX_N=1e7+5; int main(){ ll t; cin>>t; while(t--){ ll a, b; cin>>a>>b; ll ans=0; ll a1=max(a,b); ll a2=min(a,b); if(a1*2==b){ cout<<a1<<" "<<0<<endl; } else if(a1==a2){ cout<<0<<" "<<0<<endl; } else{ ll ans1=0; ll ans2=0; ans1=a1-a2; ll k1=0;ll k2=0; k1=a2%ans1; k2=a2/ans1; k1=min(k1,(k2+1)*ans1-a2); cout<<ans1<<" "<<k1<<endl; // else cout<<ans1<<" "<<a2<<endl; } } }
### Prompt Your task is to create a CPP solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define ll long long ll const MAX_N=1e7+5; int main(){ ll t; cin>>t; while(t--){ ll a, b; cin>>a>>b; ll ans=0; ll a1=max(a,b); ll a2=min(a,b); if(a1*2==b){ cout<<a1<<" "<<0<<endl; } else if(a1==a2){ cout<<0<<" "<<0<<endl; } else{ ll ans1=0; ll ans2=0; ans1=a1-a2; ll k1=0;ll k2=0; k1=a2%ans1; k2=a2/ans1; k1=min(k1,(k2+1)*ans1-a2); cout<<ans1<<" "<<k1<<endl; // else cout<<ans1<<" "<<a2<<endl; } } } ```
#include<iostream> #include<algorithm> #include<string> #include<cstring> #include<cstdio> #include<stdio.h> #include<cmath> #include<math.h> #include<vector> #include<set> #include<queue> #include<map> #include<sstream> #include<iomanip> #define forn(i,n) for(int (i)=0;i<(n);i++) #define pb push_back #define mp make_pair using namespace std; typedef pair<int,int>pii; typedef long long ll; typedef pair<ll,ll> pll; const int MAXN=100005; const int INF=2147483647; const ll LINF=9223372036854775807; const int dx[]={1,-1,0,0},dy[]={0,0,1,-1}; int tt; ll mod(ll x,ll y) { ll res=x%y; if(res<0)res+=y; return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>tt; while(tt--) { ll a,b; cin>>a>>b; if(a<b)swap(a,b); ll x=a-b; if(x==0)cout<<0<<' '<<0<<endl; else cout<<x<<' '<<min(min(mod(a,x),mod(x-a,x)),min(mod(b,x),mod(x-b,x)))<<endl; } // cout<<mod(-2,3)<<' '<<(-2)%3; return 0; }
### Prompt Please provide a cpp coded solution to the problem described below: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<iostream> #include<algorithm> #include<string> #include<cstring> #include<cstdio> #include<stdio.h> #include<cmath> #include<math.h> #include<vector> #include<set> #include<queue> #include<map> #include<sstream> #include<iomanip> #define forn(i,n) for(int (i)=0;i<(n);i++) #define pb push_back #define mp make_pair using namespace std; typedef pair<int,int>pii; typedef long long ll; typedef pair<ll,ll> pll; const int MAXN=100005; const int INF=2147483647; const ll LINF=9223372036854775807; const int dx[]={1,-1,0,0},dy[]={0,0,1,-1}; int tt; ll mod(ll x,ll y) { ll res=x%y; if(res<0)res+=y; return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>tt; while(tt--) { ll a,b; cin>>a>>b; if(a<b)swap(a,b); ll x=a-b; if(x==0)cout<<0<<' '<<0<<endl; else cout<<x<<' '<<min(min(mod(a,x),mod(x-a,x)),min(mod(b,x),mod(x-b,x)))<<endl; } // cout<<mod(-2,3)<<' '<<(-2)%3; return 0; } ```
#include<bits/stdc++.h> using namespace std; #define rep(i,a,n) for(int i=a;i<n;i++) #define brep(i,a) for(int i=a;i>=0;i--) #define all(x) x.begin(),x.end() #define allara(x,n) x,x+n #define testcase(x) int x; cin>>x; while(x--) #define vec vector<int> #define vectorpair vector<pair<int,int>> #define Fast_Read ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define MAX 1000000007 #define mod 1000000007 #define endl "\n" using ll = long long int; //..............................................// int main() { testcase(x) { ll a, b, diff, add, sub; cin>>a>>b; if (a == b) { cout << 0 << " " << 0 << endl; } else if (a == 0) cout << b << " " << 0 << endl; else if (b == 0) cout << a << " " << 0 << endl; else { diff = abs(a - b); sub = a % diff; add=((a/diff+1)*diff)-a; cout<<diff<<" "<<min(add,sub)<<endl; } } }
### Prompt Your challenge is to write a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define rep(i,a,n) for(int i=a;i<n;i++) #define brep(i,a) for(int i=a;i>=0;i--) #define all(x) x.begin(),x.end() #define allara(x,n) x,x+n #define testcase(x) int x; cin>>x; while(x--) #define vec vector<int> #define vectorpair vector<pair<int,int>> #define Fast_Read ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define MAX 1000000007 #define mod 1000000007 #define endl "\n" using ll = long long int; //..............................................// int main() { testcase(x) { ll a, b, diff, add, sub; cin>>a>>b; if (a == b) { cout << 0 << " " << 0 << endl; } else if (a == 0) cout << b << " " << 0 << endl; else if (b == 0) cout << a << " " << 0 << endl; else { diff = abs(a - b); sub = a % diff; add=((a/diff+1)*diff)-a; cout<<diff<<" "<<min(add,sub)<<endl; } } } ```
#include<bits/stdc++.h> using namespace std; #define int long long int t, a, b; signed main() { for(cin >> t; t--; ) { cin >> a >> b; if(a == b) { cout << "0 0\n"; continue; } if(a < b) swap(a, b); int ans = a - b; cout << ans << " " << min(ans-b%ans, b%ans) << "\n"; } }
### Prompt Construct a CPP code solution to the problem outlined: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define int long long int t, a, b; signed main() { for(cin >> t; t--; ) { cin >> a >> b; if(a == b) { cout << "0 0\n"; continue; } if(a < b) swap(a, b); int ans = a - b; cout << ans << " " << min(ans-b%ans, b%ans) << "\n"; } } ```
#include<iostream> #include<algorithm> #include<cmath> using namespace std; typedef long long LL; LL gcd(LL a,LL b){ return b ? gcd(b,b%a) : a; } void solve(){ LL x,y; cin>>x>>y; if(x<y)swap(x,y); if(x==y)cout<<"0 0"<<endl; else{ LL t = x - y; LL l = 0,r = 1e18 / t+1; while(l<r){ LL mid = (l+r)/2; if(t*mid > y)r=mid; else l=mid+1; } LL s = min(l*t-y,y-(l-1)*t); cout<<t<<" "<<s<<endl; } } int main(){ int T; cin>>T;while(T--)solve(); }
### Prompt Your challenge is to write a Cpp solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include<iostream> #include<algorithm> #include<cmath> using namespace std; typedef long long LL; LL gcd(LL a,LL b){ return b ? gcd(b,b%a) : a; } void solve(){ LL x,y; cin>>x>>y; if(x<y)swap(x,y); if(x==y)cout<<"0 0"<<endl; else{ LL t = x - y; LL l = 0,r = 1e18 / t+1; while(l<r){ LL mid = (l+r)/2; if(t*mid > y)r=mid; else l=mid+1; } LL s = min(l*t-y,y-(l-1)*t); cout<<t<<" "<<s<<endl; } } int main(){ int T; cin>>T;while(T--)solve(); } ```
#include <bits/stdc++.h> using namespace std; void solve(){ long long a,b; cin>>a>>b; if(a==b) cout<<0<<" "<<0<<endl; else{ cout<< abs(a-b)<<" "<<min(a%abs(a-b), abs(a-b)-a%abs(a-b))<<endl; } } int main() { int t = 1; cin >> t; while (t--){ solve(); } return 0; }
### Prompt Please create a solution in Cpp to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> using namespace std; void solve(){ long long a,b; cin>>a>>b; if(a==b) cout<<0<<" "<<0<<endl; else{ cout<< abs(a-b)<<" "<<min(a%abs(a-b), abs(a-b)-a%abs(a-b))<<endl; } } int main() { int t = 1; cin >> t; while (t--){ solve(); } return 0; } ```
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, a, b) for (int i = (a); i > (b); --i) #define ALL(x) x.begin(), x.end() #define F first #define S second #define PB push_back #define MP make_pair using namespace std; using ll = long long; using ld = long double; typedef vector<int> vi; typedef pair<int, int> pi; void fast_io() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } /* ---------- Code here ---------- */ void solve() { ll a, b; cin >> a >> b; if (a == b) { cout << "0 0\n"; return; } ll x = max(a, b), y = min(a, b); if (a == 0 || b == 0) { cout << x << " 0\n"; return; } ll z = x - y; ll q = x % z, w = z - q; cout << z << " " << min(q, w) << "\n"; } /* ---------- Main here ---------- */ int main() { fast_io(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int T; cin >> T; while (T--) { solve(); } return 0; }
### Prompt Your task is to create a CPP solution to the following problem: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations: 1. Increase both a and b by 1. 2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it. Note that gcd(x,0)=x for any x ≥ 0. Input The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases. The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}). Output For each test case, print a single line containing two integers. If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement. Example Input 4 8 5 1 2 4 4 3 9 Output 3 1 1 0 0 0 6 3 Note For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible. For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation. For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times. For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6. ### Response ```cpp #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, a, b) for (int i = (a); i > (b); --i) #define ALL(x) x.begin(), x.end() #define F first #define S second #define PB push_back #define MP make_pair using namespace std; using ll = long long; using ld = long double; typedef vector<int> vi; typedef pair<int, int> pi; void fast_io() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } /* ---------- Code here ---------- */ void solve() { ll a, b; cin >> a >> b; if (a == b) { cout << "0 0\n"; return; } ll x = max(a, b), y = min(a, b); if (a == 0 || b == 0) { cout << x << " 0\n"; return; } ll z = x - y; ll q = x % z, w = z - q; cout << z << " " << min(q, w) << "\n"; } /* ---------- Main here ---------- */ int main() { fast_io(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int T; cin >> T; while (T--) { solve(); } return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 1; return 0; } cout << n * (n - 1) * 6 + 1; return 0; }
### Prompt Please provide a cpp coded solution to the problem described below: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 1; return 0; } cout << n * (n - 1) * 6 + 1; return 0; } ```
#include <bits/stdc++.h> using namespace std; const int N = int(300000) + 5; long long int k, n, m, t, cnt, sum, ans, x, y; long long int a[N], b[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; if (n == 1) { cout << 1; return 0; } cnt = 1; while (n > 1) { sum += 12; cnt += sum; n--; } cout << cnt; return 0; }
### Prompt In CPP, your task is to solve the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; const int N = int(300000) + 5; long long int k, n, m, t, cnt, sum, ans, x, y; long long int a[N], b[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; if (n == 1) { cout << 1; return 0; } cnt = 1; while (n > 1) { sum += 12; cnt += sum; n--; } cout << cnt; return 0; } ```
#include <bits/stdc++.h> using namespace std; int ans = 1, n; int main() { cin >> n; ans = (2 * n - 1) * (2 * n - 1) + 4 * (n - 1) * (n) / 2; cout << ans; return 0; }
### Prompt In CPP, your task is to solve the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int ans = 1, n; int main() { cin >> n; ans = (2 * n - 1) * (2 * n - 1) + 4 * (n - 1) * (n) / 2; cout << ans; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int res = 1; for (int i = 1, t = 12; i < n; i++, t += 12) res += t; cout << res << endl; return 0; }
### Prompt Your task is to create a cpp solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int res = 1; for (int i = 1, t = 12; i < n; i++, t += 12) res += t; cout << res << endl; return 0; } ```
#include <bits/stdc++.h> int main(int argc, char *argv[]) { int n; scanf("%d", &n); printf("%d\n", 6 * n * (n - 1) + 1); return 0; }
### Prompt Construct a Cpp code solution to the problem outlined: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int main(int argc, char *argv[]) { int n; scanf("%d", &n); printf("%d\n", 6 * n * (n - 1) + 1); return 0; } ```
#include <bits/stdc++.h> int main() { int n, a[20000], i, s = 0; scanf("%d", &n); a[1] = 1; for (i = 2; i <= n; i++) { a[i] = 12 * (i - 1); s += a[i]; } printf("%d", s + 1); return 0; }
### Prompt Your challenge is to write a cpp solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int main() { int n, a[20000], i, s = 0; scanf("%d", &n); a[1] = 1; for (i = 2; i <= n; i++) { a[i] = 12 * (i - 1); s += a[i]; } printf("%d", s + 1); return 0; } ```
#include <bits/stdc++.h> int main() { long long int n, i, c = 0; scanf("%I64d", &n); printf("%I64d", 6 * n * (n - 1) + 1); return 0; }
### Prompt Construct a CPP code solution to the problem outlined: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int main() { long long int n, i, c = 0; scanf("%I64d", &n); printf("%I64d", 6 * n * (n - 1) + 1); return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int m, n, i, j, k, a, b; scanf("%d", &a); if (a == 1) printf("1\n"); else { printf("%d\n", (a - 1) * a / 2 * 12 + 1); } }
### Prompt Your task is to create a Cpp solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int m, n, i, j, k, a, b; scanf("%d", &a); if (a == 1) printf("1\n"); else { printf("%d\n", (a - 1) * a / 2 * 12 + 1); } } ```
#include <bits/stdc++.h> const long long int INF = 1e15; using namespace std; const long long int MAX = 1e7 + 5; const long long int mod = 1e9 + 7; long long int gcd(long long int a, long long int b) { while (b > 0) { a = a % b; swap(a, b); } return a; } long long int binpow(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b % 2 == 1) res = res * a % mod; a = a * a % mod; b /= 2; } return res % mod; } void solve() { long long int n; cin >> n; long long int ans = 3 * n * n - 2 + 3 * (n - 1) * (n - 1); cout << ans << "\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t = 1; for (long long int i = 1; i <= t; i++) { solve(); } }
### Prompt Please provide a Cpp coded solution to the problem described below: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> const long long int INF = 1e15; using namespace std; const long long int MAX = 1e7 + 5; const long long int mod = 1e9 + 7; long long int gcd(long long int a, long long int b) { while (b > 0) { a = a % b; swap(a, b); } return a; } long long int binpow(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b % 2 == 1) res = res * a % mod; a = a * a % mod; b /= 2; } return res % mod; } void solve() { long long int n; cin >> n; long long int ans = 3 * n * n - 2 + 3 * (n - 1) * (n - 1); cout << ans << "\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t = 1; for (long long int i = 1; i <= t; i++) { solve(); } } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 1 + 6 * n * (n - 1); return 0; }
### Prompt Please create a solution in CPP to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 1 + 6 * n * (n - 1); return 0; } ```
#include <bits/stdc++.h> int main() { int n, aux; scanf("%d", &n); aux = 1; for (int i = 2; i <= n; i++) aux += 12 * (i - 1); printf("%d", aux); return 0; }
### Prompt Please formulate a CPP solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int main() { int n, aux; scanf("%d", &n); aux = 1; for (int i = 2; i <= n; i++) aux += 12 * (i - 1); printf("%d", aux); return 0; } ```
#include <bits/stdc++.h> using namespace std; long star(int a) { if (a == 1) return 1; else return star(a - 1) + 12 * (a - 1); } int main() { int n; cin >> n; cout << star(n) << endl; }
### Prompt Your task is to create a Cpp solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; long star(int a) { if (a == 1) return 1; else return star(a - 1) + 12 * (a - 1); } int main() { int n; cin >> n; cout << star(n) << endl; } ```
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); printf("%d", 6 * n * (n - 1) + 1); return 0; }
### Prompt Your task is to create a CPP solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int main() { int n; scanf("%d", &n); printf("%d", 6 * n * (n - 1) + 1); return 0; } ```
#include <bits/stdc++.h> int dr[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dc[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int dr_y[] = {-1, 0, 1, 0}; int dc_x[] = {0, 1, 0, -1}; int f[100000]; using namespace std; void init() { int i; f[1] = 1; for (int i = 2; i <= 18257; i++) f[i] = f[i - 1] + (i - 1) * 12; } int main() { int n; init(); while (scanf("%d", &n) != EOF) printf("%d\n", f[n]); return 0; }
### Prompt Generate a CPP solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int dr[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dc[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int dr_y[] = {-1, 0, 1, 0}; int dc_x[] = {0, 1, 0, -1}; int f[100000]; using namespace std; void init() { int i; f[1] = 1; for (int i = 2; i <= 18257; i++) f[i] = f[i - 1] + (i - 1) * 12; } int main() { int n; init(); while (scanf("%d", &n) != EOF) printf("%d\n", f[n]); return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 6 * n * (n - 1) + 1 << endl; return 0; }
### Prompt Create a solution in cpp for the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 6 * n * (n - 1) + 1 << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; cout << (n * (n - 1) * 6) + 1 << endl; return 0; }
### Prompt Construct a CPP code solution to the problem outlined: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; cout << (n * (n - 1) * 6) + 1 << endl; return 0; } ```
#include <bits/stdc++.h> #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("O8") #pragma GCC optimization("unroll-loops") using namespace std; const long long int N = 1e6 + 20, mod = 1e9 + 7, inf = 2e18, dlt = 12250, maxm = 524288; int main() { long long n; cin >> n; cout << 1 + 6 * n * (n - 1); }
### Prompt In CPP, your task is to solve the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("O8") #pragma GCC optimization("unroll-loops") using namespace std; const long long int N = 1e6 + 20, mod = 1e9 + 7, inf = 2e18, dlt = 12250, maxm = 524288; int main() { long long n; cin >> n; cout << 1 + 6 * n * (n - 1); } ```
#include <bits/stdc++.h> using namespace std; int main() { long long sl, sB, k; cin >> k; sl = k - 1; sB = k * 3 - 2; cout << ((sB + 1) * sB) / 2 + 3 * ((sl + 1) * sl) / 2; return 0; }
### Prompt Please formulate a CPP solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { long long sl, sB, k; cin >> k; sl = k - 1; sB = k * 3 - 2; cout << ((sB + 1) * sB) / 2 + 3 * ((sl + 1) * sl) / 2; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main(int argc, const char *argv[]) { int n; cin >> n; cout << 12 * (n - 1) + 6 * (n - 1) * (n - 2) + 1; return 0; }
### Prompt Please create a solution in CPP to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main(int argc, const char *argv[]) { int n; cin >> n; cout << 12 * (n - 1) + 6 * (n - 1) * (n - 2) + 1; return 0; } ```
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { return (y == 0) ? x : gcd(y, x % y); } unsigned long long lcm(long long x, long long y) { return x / gcd(x, y) * y; } void the_end() {} int dy8[] = {0, 0, 1, -1, 1, -1, -1, 1}; int dx8[] = {1, -1, 0, 0, 1, -1, 1, -1}; int id8[] = {0, 1, 2, 3, 4, 5, 6, 7}; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long a; cin >> a; cout << 6 * a * (a - 1) + 1 << '\n'; the_end(); }
### Prompt Create a solution in cpp for the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { return (y == 0) ? x : gcd(y, x % y); } unsigned long long lcm(long long x, long long y) { return x / gcd(x, y) * y; } void the_end() {} int dy8[] = {0, 0, 1, -1, 1, -1, -1, 1}; int dx8[] = {1, -1, 0, 0, 1, -1, 1, -1}; int id8[] = {0, 1, 2, 3, 4, 5, 6, 7}; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long a; cin >> a; cout << 6 * a * (a - 1) + 1 << '\n'; the_end(); } ```
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; template <class T> double sqrt(T x) { return sqrt((double)x); } template <class T> T sqr(T x) { return x * x; } const double PI = acos(-1.0); const int INF = 1000000000; const int MOD = 1000000007; void wa() { cout << 5; exit(0); } void tl() { while (1) ; } void pe() { cout << "abc abc\n 453534 wff sf sd\n"; exit(0); } void re() { exit(1); } void ml() { int *b = new int[1000]; } int main() { double TIME_START = clock(); int n; cin >> n; unsigned long long ans = 1, lay; if (n >= 2) { lay = 12; for (int x = 2; x <= n; x++) { ans += lay; lay += 12; } } cout << ans; fprintf(stderr, "\n\n%.15lf\n\n", (double)(clock() - TIME_START) / CLOCKS_PER_SEC); return 0; }
### Prompt Create a solution in CPP for the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; template <class T> double sqrt(T x) { return sqrt((double)x); } template <class T> T sqr(T x) { return x * x; } const double PI = acos(-1.0); const int INF = 1000000000; const int MOD = 1000000007; void wa() { cout << 5; exit(0); } void tl() { while (1) ; } void pe() { cout << "abc abc\n 453534 wff sf sd\n"; exit(0); } void re() { exit(1); } void ml() { int *b = new int[1000]; } int main() { double TIME_START = clock(); int n; cin >> n; unsigned long long ans = 1, lay; if (n >= 2) { lay = 12; for (int x = 2; x <= n; x++) { ans += lay; lay += 12; } } cout << ans; fprintf(stderr, "\n\n%.15lf\n\n", (double)(clock() - TIME_START) / CLOCKS_PER_SEC); return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int num; long long result; cin >> num; result = 6 * num * (num - 1) + 1; cout << result; return 0; }
### Prompt Your task is to create a cpp solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int num; long long result; cin >> num; result = 6 * num * (num - 1) + 1; cout << result; return 0; } ```
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int add = 0; long long total = 1; for (int i = 0; i < n; i++) { total += add; add += 12; } printf("%I64d\n", total); return 0; }
### Prompt Please create a solution in CPP to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int add = 0; long long total = 1; for (int i = 0; i < n; i++) { total += add; add += 12; } printf("%I64d\n", total); return 0; } ```
#include <bits/stdc++.h> int main() { int n; std::cin >> n; std::cout << 6 * n * (n - 1) + 1; }
### Prompt Please formulate a CPP solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int main() { int n; std::cin >> n; std::cout << 6 * n * (n - 1) + 1; } ```
#include <bits/stdc++.h> using namespace std; int main() { long a, S, i; for (cin >> a, i = 0, S = 0; i < 1; S += (6 * a * (a - 1) + 1), cout << S, ++i) ; return 0; }
### Prompt Your challenge is to write a CPP solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { long a, S, i; for (cin >> a, i = 0, S = 0; i < 1; S += (6 * a * (a - 1) + 1), cout << S, ++i) ; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (6 * n * (n - 1)) + 1; return 0; }
### Prompt Construct a CPP code solution to the problem outlined: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (6 * n * (n - 1)) + 1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; long long n, ans; while (t--) { cin >> n; cout << (6 * n * (n - 1)) + 1; } return 0; }
### Prompt Your challenge is to write a cpp solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; long long n, ans; while (t--) { cin >> n; cout << (6 * n * (n - 1)) + 1; } return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { long long int N; cin >> N; cout << (N * (N - 1) * 6) + 1 << endl; }
### Prompt Please provide a CPP coded solution to the problem described below: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { long long int N; cin >> N; cout << (N * (N - 1) * 6) + 1 << endl; } ```
#include <bits/stdc++.h> using namespace std; int MAX(long long int a, long long int b) { if (a > b) { return a; } else { return b; } } int MIN(long long int a, long long int b) { if (a < b) { return a; } else { return b; } } int gcd(long long int a, long long int b) { long long int c; while (a != 0) { c = a; a = b % a; b = c; } return b; } int main() { int n; cin >> n; cout << (6 * n * (n - 1)) + 1 << endl; return 0; }
### Prompt In CPP, your task is to solve the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int MAX(long long int a, long long int b) { if (a > b) { return a; } else { return b; } } int MIN(long long int a, long long int b) { if (a < b) { return a; } else { return b; } } int gcd(long long int a, long long int b) { long long int c; while (a != 0) { c = a; a = b % a; b = c; } return b; } int main() { int n; cin >> n; cout << (6 * n * (n - 1)) + 1 << endl; return 0; } ```
#include <bits/stdc++.h> int main() { unsigned long int a, sum = 1, i; scanf("%lu", &a); for (i = 2; i <= a; i++) { sum += (i - 1) * 12; } printf("%lu", sum); return 0; }
### Prompt Please provide a CPP coded solution to the problem described below: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int main() { unsigned long int a, sum = 1, i; scanf("%lu", &a); for (i = 2; i <= a; i++) { sum += (i - 1) * 12; } printf("%lu", sum); return 0; } ```
#include <bits/stdc++.h> int main() { long long a; scanf("%I64d", &a); if (a == 1) puts("1"); else printf("%I64d\n", a * (a - 1) * 6 + 1); return 0; }
### Prompt Construct a Cpp code solution to the problem outlined: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int main() { long long a; scanf("%I64d", &a); if (a == 1) puts("1"); else printf("%I64d\n", a * (a - 1) * 6 + 1); return 0; } ```
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long MAX = 1e17; int main() { ios_base::sync_with_stdio(0); ; int n; cin >> n; n = 1 + 6 * n * (n - 1); cout << n << endl; ; return 0; }
### Prompt Develop a solution in Cpp to the problem described below: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long MAX = 1e17; int main() { ios_base::sync_with_stdio(0); ; int n; cin >> n; n = 1 + 6 * n * (n - 1); cout << n << endl; ; return 0; } ```
#include <bits/stdc++.h> using namespace std; long long star(int n) { if (n == 1) return 1; else return 12 * n - 12 + star(n - 1); } int main() { int n; cin >> n; cout << star(n); return 0; }
### Prompt Your challenge is to write a Cpp solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; long long star(int n) { if (n == 1) return 1; else return 12 * n - 12 + star(n - 1); } int main() { int n; cin >> n; cout << star(n); return 0; } ```
#include <bits/stdc++.h> using namespace std; int A[19000] = {0}; int main() { int a; cin >> a; A[0] = 1; for (int i = 1; i < a; i++) A[i] = A[i - 1] + 6 + 6 * (2 * i - 1); cout << A[a - 1] << endl; }
### Prompt Please create a solution in CPP to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int A[19000] = {0}; int main() { int a; cin >> a; A[0] = 1; for (int i = 1; i < a; i++) A[i] = A[i - 1] + 6 + 6 * (2 * i - 1); cout << A[a - 1] << endl; } ```
#include <bits/stdc++.h> int main() { int n; long long int s; scanf("%d", &n); s = 6 * n * (n - 1) + 1; printf("%I64d", s); return 0; }
### Prompt Please formulate a Cpp solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int main() { int n; long long int s; scanf("%d", &n); s = 6 * n * (n - 1) + 1; printf("%I64d", s); return 0; } ```
#include <bits/stdc++.h> using namespace std; void loadData(void); int proc(void); void printRes(int); int a; int main(int argc, char** argv) { loadData(); printRes(proc()); return 0; } int proc(void) { long long res = 0; res += (long long)(a + a + a - 1) * (long long)a / (long long)2; res += (long long)(a + a + a - 2) * (long long)(a - 1) / (long long)2; res += (long long)(1 + a - 1) * (long long)(a - 1) * (long long)3; return (int)(res % (long long)(2000000000)); } void loadData(void) { scanf("%d", &a); return; } void printRes(int res) { printf("%d\n", res); return; }
### Prompt Your challenge is to write a cpp solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; void loadData(void); int proc(void); void printRes(int); int a; int main(int argc, char** argv) { loadData(); printRes(proc()); return 0; } int proc(void) { long long res = 0; res += (long long)(a + a + a - 1) * (long long)a / (long long)2; res += (long long)(a + a + a - 2) * (long long)(a - 1) / (long long)2; res += (long long)(1 + a - 1) * (long long)(a - 1) * (long long)3; return (int)(res % (long long)(2000000000)); } void loadData(void) { scanf("%d", &a); return; } void printRes(int res) { printf("%d\n", res); return; } ```
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { int n; scanf("%d", &n); n--; printf("%d\n", (int)(1 + (long long)(n + 1) * (long long)n * 6)); return 0; }
### Prompt Create a solution in Cpp for the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { int n; scanf("%d", &n); n--; printf("%d\n", (int)(1 + (long long)(n + 1) * (long long)n * 6)); return 0; } ```
#include <bits/stdc++.h> using namespace std; long long n, s; int main() { cin >> n; s = 6 * n * (n - 1) + 1; cout << s; }
### Prompt Please formulate a cpp solution to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; long long n, s; int main() { cin >> n; s = 6 * n * (n - 1) + 1; cout << s; } ```
#include <bits/stdc++.h> using namespace std; int A[10]; int main() { int n, m, i, s = 1; cin >> n; cout << 6 * n * (n - 1) + 1; return 0; }
### Prompt Construct a cpp code solution to the problem outlined: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int A[10]; int main() { int n, m, i, s = 1; cin >> n; cout << 6 * n * (n - 1) + 1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int a; scanf("%d", &a); printf("%d\n", 6 * a * (a - 1) + 1); return 0; }
### Prompt Please create a solution in Cpp to the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int a; scanf("%d", &a); printf("%d\n", 6 * a * (a - 1) + 1); return 0; } ```
#include <bits/stdc++.h> int main(void) { int n; scanf("%d", &n); n--; long m = n * (n + 1) / 2; m *= 12; m++; printf("%I32d", m); return 0; }
### Prompt Develop a solution in Cpp to the problem described below: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> int main(void) { int n; scanf("%d", &n); n--; long m = n * (n + 1) / 2; m *= 12; m++; printf("%I32d", m); return 0; } ```
#include <bits/stdc++.h> using namespace std; long long a; int main() { scanf("%lld", &a); printf("%lld", 1 + 12 * (a * (a - 1) / 2)); return 0; }
### Prompt Please provide a Cpp coded solution to the problem described below: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; long long a; int main() { scanf("%lld", &a); printf("%lld", 1 + 12 * (a * (a - 1) / 2)); return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans = 0; for (int i = 1; i < n; i++) ans += i * 12; cout << ans + 1; return 0; }
### Prompt In cpp, your task is to solve the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans = 0; for (int i = 1; i < n; i++) ans += i * 12; cout << ans + 1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; if (a == 1) { cout << 1; return 0; } cout << (a - 1) * a * 6 + 1; }
### Prompt In Cpp, your task is to solve the following problem: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; if (a == 1) { cout << 1; return 0; } cout << (a - 1) * a * 6 + 1; } ```