EOJ Monthly 2017.12

来源:互联网 发布:淘宝网的赌石是真的吗 编辑:程序博客网 时间:2024/06/05 02:48

B. 在哈尔滨的寒风中

Time limit per test: 1.0 seconds

Memory limit: 256 megabytes

kblack 来到了寒冬中的哈尔滨,哈尔滨的寒风令 kblack 瑟瑟发抖。

世界上最远的距离,是你与宾馆只差一条冰街,而你却忘了穿上秋裤。

kblack 终于冲进了宾馆,宾馆大厅的地板铺满了五颜六色的地砖,可以被看作是一块 n×m 格的棋盘,为了能使冻僵了的双脚尽快暖和起来,kblack 决定在地砖上走动,但是他被速冻的双脚在棋盘地板上只能走马步。

kblack 居然想知道有多少对地砖(无序点对)他可以通过若干步马步互相抵达!

Input

输入包含一行两个正整数 nm,表示棋盘的大小,保证 1n×m109 。

Output

输出包含一个整数,表示 kblack 可以通过马步互相到达的无序地砖对数。

Examples

input
1 2
output
0
input
4 2
output
4
画一画

n=1 2 3 4 m= 1 2 3 4

就能发现规律。


先让n<=m。

当n>=3时,全部可以走到,就是c(n*m,2),特殊的有n=3,m=3.

当n==2时,答案也可以计算出来。

当n==1时,为0 。


#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define LL long longconst int maxn  = 1e5+55;int main(){int n,m;scanf("%d %d",&n,&m);if(n>m) swap(n, m);if(n==1){printf("0\n");//}else if(n==2&&m==3){//printf("2\n");//}else if (n==2&&m==4){//printf("4\n");}else if(n==2){LL a=1LL*(m+1)/2;LL b=1LL*m/2;printf("%lld\n",a*(a-1)+b*(b-1));}else if(n==3&m==3){printf("28\n");}else{LL x=1LL*n;LL y=1LL*m;printf("%lld\n",(x*y)*(x*y-1)/2);}}


原创粉丝点击