1+
2+ #include < bits/stdc++.h>
3+ #include < unordered_set>
4+ #include < chrono>
5+ #define ll long long
6+ #define int long long
7+ #define MOD1 998244353
8+ #define INF 1e18
9+ #define endl " \n "
10+ #define vi vector<int >
11+ #define pb push_back
12+ #define vvi vector<vector<int >>
13+ #define pii pair<int , int >
14+ #define ff first
15+ #define ss second
16+ #define ss second
17+ #define PI 3.141592653589793238462
18+ #define set_bits __builtin_popcountll
19+ #define sz (x ) ((int )(x).size())
20+ #define all (x ) (x).begin(), (x).end()
21+ #define f (i,a,b ) for (ll i=a;i<b;i++)
22+
23+ #define amax (a ) *max_element (a, a + n)
24+ #define amin (a ) *min_element (a, a + n)
25+ #define vmax (a ) *max_element (a.begin(), a.end())
26+ #define vmin (a ) *min_element (a.begin(), a.end())
27+ using namespace std;
28+ #define watch (x ) cout << (#x) << " = " << (x) << endl
29+ const int MOD = 1e9 + 7 ;
30+ ll gcd (ll a, ll b) {if (b > a) {return gcd (b, a);} if (b == 0 ) {return a;} return gcd (b, a % b);}
31+ ll mult (ll x, ll y) {ll res = x * y;return (res >= MOD ? res % MOD : res);}
32+ ll factorial (ll v){ll ans=1 ;for (int i=2 ;i<=v;i++){ans*=i;ans%=MOD ;}return ans;}
33+ ll power (ll a, ll n){ll res = 1 ;while (n){if (n%2 == 1 ){res = (res * a)%MOD ;n--;}else {a = (a * a)%MOD ;n = n/2 ;}}return res;}
34+ 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;}
35+ void vin ( vector<int > &v , int n ){for (int i = 0 ; i < n; i++){int x ;cin >> x; v.push_back (x);}}
36+ void vout (vector<int > &v){for (int i = 0 ; i < v.size (); i++){cout << v[i] << " " ;}cout << endl;}
37+ ll highestPowerof2 (ll n){ ll p = (ll)log2 (n); return (ll)pow (2 , p);}
38+ bool isPowerOfTwo (int n){ if (n==0 ) return false ; return (ceil (log2 (n)) == floor (log2 (n)));}
39+ bool chkprime (int n){ for (int i = 2 ; i*i <= n ; i++){ if ( n % i == 0 ) return false ;} return true ; }
40+ string to_binary (int n) { string s = " " ; for (int i = 31 ; i >= 0 ; i--) { int k = n >> i; if (k & 1 ) s = s + " 1" ;else s = s + " 0" ;}return s ; }
41+ static void removeTrailingCharacters (std::string &str, const char charToRemove) {str.erase (str.find_last_not_of (charToRemove) + 1 , std::string::npos );}
42+ static void removeLeadingCharacters (std::string &str, const char charToRemove) {str.erase (0 , std::min (str.find_first_not_of (charToRemove), str.size () - 1 ));}
43+ long long lcm (int a, int b){ return (a / gcd (a, b)) * b;}
44+ int digits_count (int n){int d=0 ;while (n != 0 ){d++;n /=10 ;}return d;}
45+ vector<string> to_token (string s){vector<string> tokens; stringstream chk1 (s); string tmp; while (getline (chk1, tmp, ' ' )){ tokens.push_back (tmp); } return tokens;}
46+ vector<int > findFactors (int n){vector<int > v;for (int i=1 ; i<=sqrt (n); i++){if (n%i == 0 ){if (n/i == i)v.pb (i);else {v.pb (i);v.pb (n/i);}}}sort (all (v));return v;}
47+
48+ void prakhar () {
49+
50+ int a, b ;
51+ cin >> a >> b ;
52+
53+
54+
55+ if (a == 1 && b == 1 ){
56+ cout << 1 << endl;
57+ cout <<a << " " << b << endl;
58+ return ;
59+ }
60+ if (a == -1 && b == 1 ){
61+ cout << 1 << endl;
62+ cout <<a << " " << b << endl;
63+
64+ return ;
65+ }
66+ if (a == 1 && b == -1 ){
67+ cout << 1 << endl;
68+ cout <<a << " " << b << endl;
69+
70+ return ;
71+ }
72+ if (a == -1 && b == -1 ){
73+ cout << 1 << endl;
74+ cout <<a << " " << b << endl;
75+
76+ return ;
77+ }
78+
79+ if (gcd (a, b) == 1 ){
80+ cout << 1 << endl;
81+ cout << a << " " << b << endl;
82+ return ;
83+ }
84+
85+ cout << 2 << endl;
86+
87+ cout << a - 1 << " " << 1 << endl;
88+ cout << a << " " << b << endl;
89+ return ;
90+
91+
92+ if (a-1 != b + 1 && a-1 != 0 && b+1 != 0 && gcd (a-1 , b+1 ) == 1 && a -1 <= 1000000000 && b+ 1 <= 1000000000 ){
93+ cout << a-1 << " " << b+1 << endl;
94+
95+ cout << a << " " << b << endl;
96+ return ;
97+ }
98+ if (a-1 != b - 1 && a-1 != 0 && b-1 != 0 && gcd (a-1 , b-1 ) == 1 && a-1 <= 1000000000 && b-1 <= 1000000000 ){
99+ cout << a-1 << " " << b-1 << endl;
100+
101+ cout << a << " " << b << endl;
102+ return ;
103+ }
104+ if (a + 1 != b + 1 && a+1 != 0 && b+1 != 0 && gcd (a+1 , b+1 ) == 1 && a+1 <= 1000000000 && b+1 <= 1000000000 ){
105+ cout << a+1 << " " << b+1 << endl;
106+
107+ cout << a << " " << b << endl;
108+ return ;
109+ }
110+ if (a+1 != b -1 && a + 1 != 0 && b -1 != 0 && gcd (a+1 , b-1 ) == 1 && a+1 <= 1000000000 && b-1 <= 1000000000 ){
111+ cout << a-1 << " " << b+1 << endl;
112+
113+ cout << a << " " << b << endl;
114+ return ;
115+ }
116+
117+ int dx[] = {+1 , 0 , -1 , 0 };
118+ int dy[] = {0 , + 1 , 0 , -1 };
119+
120+ for (int i = 0 ; i < 4 ; i++)
121+ {
122+ int x = a + dx[i];
123+ int y = b + dy[i];
124+
125+ if (x != y && x!= 0 && y != 0 && gcd (x, y) == 1 && x <= 1000000000 && y <= 1000000000 ){
126+ cout << x << " " << y << endl;
127+
128+ cout << a << " " << b << endl;
129+ return ;
130+ }
131+ }
132+
133+
134+
135+ }
136+
137+ int32_t main () {
138+ ios_base::sync_with_stdio (false );
139+ cin.tie (NULL );
140+ #ifndef ONLINE_JUDGE
141+ freopen (" input.txt" , " r" , stdin);
142+ freopen (" output.txt" , " w" , stdout);
143+ freopen (" error.txt" , " w" , stderr);
144+ #endif
145+ auto start = chrono::steady_clock::now ();
146+
147+ // Insert the code that will be timed
148+
149+
150+ ll t = 1 ;
151+ cin >> t ;
152+ int ii;
153+ for ( ii = 1 ; ii <= t; ii++) {
154+ // cout << "Case #" << i <<": ";
155+ prakhar ();
156+ }
157+
158+ auto end = chrono::steady_clock::now ();
159+
160+ auto diff = end - start;
161+ cerr << chrono::duration <double , nano> (diff).count () << " ns" << endl;
162+
163+ return 0 ;
164+
165+ }
0 commit comments