-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber Spiral.cpp
61 lines (58 loc) · 1.42 KB
/
Number Spiral.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(v) (v).begin(), (v).end()
#define fl fflush(stdout)
void solve() {
int n; cin >> n;
for (int i = 0; i < n; i++) {
int y, x; cin >> x >> y;
if (x > y) {
if (x % 2 != 0) {
x--;
cout << (x * x) + y << endl;
}
else {
cout << (x * x) - y + 1 << endl;
}
}
else {
if (y % 2 != 0) {
cout << (y * y) - x + 1 << endl;
}
else {
y--;
cout << (y * y) + x << endl;
}
}
}
}
signed main() {
auto start = high_resolution_clock::now();
IOS;
int t = 1;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r" , stdin);
freopen("output.txt", "w", stdout);
#endif
// cin >> t;
int i = 1;
while (t--) {
// cout << "CASE #" << i << ": ";
solve();
cout << endl;
i++;
}
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cerr << "Time taken:" << duration.count() / 1000000.0 << " seconds" << "\n";
return 0;
}