UVA - 11538 ——Chess Queen(推公式)

题目链接:https://vjudge.net/problem/UVA-11538

#include
#include
#include
#define LL long long
using namespace std;
int main()
{
    LL n,m;
    while(~scanf("%lld%lld",&n,&m),n||m)
    {
        if(n>m) swap(n,m);
        printf("%lld\n",n*m*(m+n-2)+2*n*(n-1)*(3*m-n-1)/3);
    }
}

 

你可能感兴趣的:(ACM白书)