Uva 11538 - Chess Queen

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2533

公式推导

代码:

 

#include <iostream>

#include <cstdio>

#include <string>

#include <cstring>

#include <cmath>

#include <algorithm>



#define ll long long

using namespace std;



int main()

{

    //freopen("data.in","r",stdin);

    ll n,m;

    while(cin>>n>>m)

    {

        if(!n&&!m)break;



        if(n>m)

        swap(n,m);

        long long sum=0;

        sum+=(n*m*(m-1));

        sum+=(m*n*(n-1));

        sum+=((n*(n-1)*(n-2)*2/3+(m-n+1)*n*(n-1)))*2;

        cout<<sum<<endl;

    }

    return 0;

}

 

 

你可能感兴趣的:(uva)