A Chess Queen

Problem A Chess Queen  Input: Standard Input

Output: Standard Output

You probably know how the game of chess is played and how chess queen operates. Two chess queens are in attacking position when they are on same row, column or diagonal of a chess board. Suppose two such chess queens (one black and the other white) are placed on (2x2) chess board. They can be in attacking positions in 12 ways, these are shown in the picture below:

 
   

Figure: in a (2x2) chessboard 2 queens can be in attacking position in 12 ways

Given an (NxM) board you will have to decide in how many ways 2 queens can be in attacking position in that.

Input

Input file can contain up to 5000 lines of inputs. Each line contains two non-negative integers which denote the value of M and N (0< M, N£106) respectively.

Input is terminated by a line containing two zeroes. These two zeroes need not be processed.

Output

For each line of input produce one line of output. This line contains an integer which denotes in how many ways two queens can be in attacking position in  an (MxN) board, where the values of M and N came from the input. All output values will fit in 64-bit signed integer.

Sample Input                              Output for Sample Input

2 2

100 223

2300 1000

0 0

12

10907100

11514134000

Problemsetter: Shahriar Manzoor

Special Thanks to: Mohammad Mahmudur Rahman

 /*
分三种情况:
同行
同列
同斜
*/ #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll; const int M=; int get(){
char c;
int res=;
while(c=getchar(),!isdigit(c));
do{
res=(res<<)+(res<<)+(c-'');
}while(c=getchar(),isdigit(c));
return res;
} int main()
{
ll ans1,ans2,ans3,ans,n,m;
while(~scanf("%lld%lld",&n,&m))
{
if(n==&m==)break;
if(n>m)swap(n,m);
ans1=n*m*(m-);//同行
ans2=n*m*(n-);//同列
ans3=*n*(n-)*(*m-n-)/;//同斜
ans=ans1+ans2+ans3;
printf("%lld\n",ans);
}
return ;
}

最新文章

  1. YY前端课程-自习
  2. C++模拟C#事件委托机制(二)
  3. 每日学习心得:SharePoint 2013 自定义列表项添加Callout菜单项、文档关注、SharePoint服务端对象模型查询
  4. POJ3264 Balanced Lineup
  5. for循环,你深刻理解了吗?
  6. 回溯(UVA129)
  7. HTML5 UTF-8 中文乱码
  8. PHP 进行统一邮箱登陆的代理实现(swoole)
  9. Oracle改变字段类型
  10. Android开发学习之路--基于vitamio的视频播放器(二)
  11. java代码之美(4)---guava之Immutable(不可变)集合
  12. oracle学习笔记第一天
  13. 四十一、Linux 线程——线程同步之条件变量
  14. java接口签名(Signature)实现方案续
  15. SAP传输请求自动发布
  16. 在windows下安装nvm并管理nodejs版本
  17. jq的事件对象
  18. jsp-servlet 的相关请求路径问题 —url
  19. 应用PLSQL Developer(技巧)
  20. Python Import机制

热门文章

  1. mysql workbench中PK,NN,UQ,BIN,UN,ZF,AI字段类型标识说明
  2. 图的深度优先搜索(DFS)和广度优先搜索(BFS)算法
  3. java学习之- 创建线程run和start特点
  4. vue基于element-ui的三级CheckBox复选框
  5. C# 使用 MsieJavaScriptEngine 引擎运行JavaScript
  6. C# DataTable 增加行与列
  7. python - del 方法
  8. EDM案例讲解:Mouth foods的EDM邮件营销
  9. web搜索功能测试
  10. SSTap | ProxyCap