Skip to content

Commit

Permalink
Add CSES problem - Number Spiral
Browse files Browse the repository at this point in the history
  • Loading branch information
ithallotulio committed Jul 24, 2024
1 parent 94b883c commit a0f6d59
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cses/introductory-problems/number-spiral.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
int t;
long long int y, x, mainDiagonal, mx, ans;
cin >> t;
while (t--) {
cin >> y >> x;
mx = max(y, x);
mainDiagonal = ((mx * mx) - mx + 1);
if (mx % 2 == 0) {
ans = mainDiagonal + y - x;
} else {
ans = mainDiagonal + x - y;
}
cout << ans << endl;
}
return 0;
}

0 comments on commit a0f6d59

Please sign in to comment.