原题链接:http://codeforces.com/contest/1047/problem/D
Little C Loves 3 II
Little C loves number «3» very much. He loves all things about it.
Now he is playing a game on a chessboard of size . The cell in the -th row and in the -th column is called . Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly . The Manhattan distance between two cells and is defined as .
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers and — the number of rows and the number of columns of the chessboard.
Output
Print one integer — the maximum number of chessmen Little C can place.
Examples
input
2 2
output
0
input
3 3
output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than , so the answer is .
In the second example, a possible solution is .
题解
这位老哥找规律实在是太强辣,甘拜下风 。
代码
#include<bits/stdc++.h>
using namespace std;
int n,m,x[]={0,0,0,0,2,4};
void in(){scanf("%d%d",&n,&m);}
void ac()
{
if(n>m)swap(n,m);
if(n==1)printf("%d",m/6*6+x[m%6]);
else if(n==2)
{
if(m==2)puts("0");
else if(m==3)puts("4");
else if(m==7)puts("12");
else printf("%lld",1ll*n*m);
}
else printf("%lld",n%2&&m%2?1ll*n*m-1:1ll*n*m);
}
int main(){in();ac();}