// 对每个(n, 1)结果都为:2 * n - 3 intcom(int n) { int com = 2 * n - 3; return com; }
// 把(n, m)转换为(n, 1), (n -2, 1)...(n - 2m + 2, 1)之和的形式并利用com()计算结果 intarr(int n, int m) { int res = 0; for (int i = 0; i < m; i++) { res += com(n - 2 * i); //cout << i <<" "<< res<<endl; } return res; }
vector<int> compute() {
int groupNum; cin >> groupNum; vector<int> output; for (int i = 0; i < groupNum; i++) { int n; int m; //cout << "choiseNum:" << choiseNum << endl; cin >> n; //cout << "b:" << b << endl; cin >> m; //cout << "c:" << c << endl; if (n == 1 || m == 0) { output.push_back(0); } else { if (2 * m < n) { int res = arr(n, m); output.push_back(res); } else { m = n / 2; int res = arr(n, m); output.push_back(res); } } } return output; }
intmain() { vector<int> res = compute(); for (int i = 0; i < res.size(); i++) { //cout << res[i]; printf("%d\n", res[i]); } return0; }