原题链接: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 n × m n×m n×m. The cell in the x x x-th row and in the y y y-th column is called ( x , y ) (x,y) (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3 3 3. The Manhattan distance between two cells ( x i , y i ) (x_i,y_i) (xi,yi) and ( x j , y j ) (x_j,y_j) (xj,yj) is defined as ∣ x i − x j ∣ + ∣ y i − y j ∣ |x_i−x_j|+|y_i−y_j| ∣xi−xj∣+∣yi−yj∣.
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 n n n and m ( 1 ≤ n , m ≤ 1 0 9 ) m (1≤n,m≤10^9) m(1≤n,m≤109) — 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 3 3 3, so the answer is 0 0 0.
In the second example, a possible solution is ( 1 , 1 ) ( 3 , 2 ) , ( 1 , 2 ) ( 3 , 3 ) , ( 2 , 1 ) ( 1 , 3 ) , ( 3 , 1 ) ( 2 , 3 ) (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3) (1,1)(3,2),(1,2)(3,3),(2,1)(1,3),(3,1)(2,3).
题解
这位老哥找规律实在是太强辣,甘拜下风 % % % \%\%\% %%%。
代码
#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();}