Hustlingbeast_Anish

Untitled

Feb 9th, 2022
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 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.         long long int y,x;
  13.         cin>>y>>x;  
  14.  
  15.         int r=y;
  16.         int c=x;
  17.         if(c>r){
  18.             if(c%2!=0){
  19.                 cout<< fixed <<pow(c,2)-(r-1)<<endl;
  20.             }
  21.             else{
  22.                 cout<< fixed <<pow(c-1,2)+1+(r-1)<<endl;
  23.             }
  24.         }
  25.  
  26.  
  27.         if(r>c){
  28.             if(r%2==0){
  29.                 cout<< fixed <<pow(r,2)-(c-1)<<endl;
  30.             }
  31.             else{
  32.                 cout<< fixed <<pow(r-1,2)+1+(c-1)<<endl;
  33.             }
  34.         }
  35.         if(r==c){
  36.             if(r%2!=0){
  37.                 cout<< fixed <<pow((r-1),2)+(c-1)<<endl;
  38.             }
  39.             else{
  40.                 cout<< fixed <<pow(r,2)-(c-1)<<endl;
  41.             }
  42.         }
  43.     }
  44. return 0;
  45. }  
Advertisement
Add Comment
Please, Sign In to add comment