直接推公式
AC代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
unsigned long long ans, n, m;
int main(){
while( cin >> n >> m && !( n == 0 && m == 0 ) ){
if( n > m ){
swap( n, m );
}
ans = m * n * ( m + n - 2 ) + 2 * n * ( n - 1 ) * ( 3 * m - n - 1 ) / 3;
cout << ans << endl;
}
return 0;
}