Educational Codeforces Round 130 Rated for Div. 2
Codeforces Round #802 Div. 2
这次没打比赛,纯补题
A Optimal Path
简单题,甚至可以用循环,但我怕爆时间,简单推个公式
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e4 + 10;
int n, m;
int T;
signed main()
{
cin>>T;
while(T -- ){
cin >> n >> m;
int op = 0;
if(m % 2) op += (m + 1) / 2 + m / 2 * (m + 1);
else op += (m + 1) * m / 2;
op -= m;
for(int i = 1; i <= n; i ++ ){
op += i * m;
}
cout<<op<<endl;
}
return 0;
}