
數學
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
//declare
int t;
//
signed main(){
// fastio;
cin>>t;
while(t--){
int row,col; cin>>row>>col;
if(row >= col){
if(row%2) cout<<(row-1)*(row-1)+1 + col - 1<<"\n";
else cout<<row*row - col + 1<<"\n";
}
if(col > row){
if(col%2) cout<<col*col - row + 1<<"\n";
else cout<<(col-1)*(col-1)+1 + row - 1<<"\n";
}
}
return 0;
}

發佈留言