Hustlingbeast_Anish

Number Spiral

Feb 15th, 2022
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(NULL);
  7.  
  8. long long int t;
  9. cin>>t;
  10.  
  11. while(t--)
  12. {
  13. long long int y,x;
  14. cin>>y>>x;
  15.  
  16. long long int r=y;
  17. long long int c=x;
  18. if(c>r){
  19. if(c%2!=0){
  20. cout<< fixed <<((c*c)-(r-1))<<endl;
  21. }
  22. if(c%2==0){
  23. cout<< fixed <<((c-1)*(c-1)+1+(r-1))<<endl;
  24. }
  25. }
  26.  
  27.  
  28. if(r>c){
  29. if(r%2==0){
  30. cout<< fixed <<((r*r)-(c-1))<<endl;
  31.  
  32. }
  33. if(r%2!=0){
  34. cout<< fixed <<(((r-1)*(r-1))+1+(c-1))<<endl;
  35. }
  36. }
  37. if(r==c)
  38. {
  39. if(r%2!=0)
  40. {
  41. cout<< fixed <<((r-1)*(r-1)+(c-1))<<endl;
  42. }
  43. if(r%2==0)
  44. {
  45. cout<< fixed <<((r*r)-(c-1))<<endl;
  46. }
  47. }
  48. }
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment