posts - 195,  comments - 30,  trackbacks - 0
There is chessboard which has N * M squares size of 1 * 1 and small squares can build up to a large one. Can you tell Mr. Guo that how many squares in the chessboard?

For Example, when N = 2 and M = 3, there are 6 squares size of 1 * 1 and 2 squares size of 2 * 2 in the chessboard, so the answer is 8.

Input

There are several lines in the input, each line consist of two positive integers N and M (1 <= N <= 100, 1 <= M <= 100) except the last line which N = 0 and M = 0 implying the end of the input and you should not process it.

Output

Please output the number of the squares for each chessboard in a single line.

Sample Input

1 1
2 3
3 3
0 0

Sample Output

1
8
14

启发:人是怎么算的,就让程序怎么算,一步一步推。
#include<iostream>
using namespace std;
int main()
{
int n,m;
long sum=0;
int i;
while(cin>>n>>m,n)
{
if(n==m)
{
sum=n*(n+1)*(2*n+1)/6;
cout<<sum<<endl;
}
else
{
for(i=0;i<n&&i<m;i++)
sum+=(n-i)*(m-i);
cout<<sum<<endl;
}
sum=0;
}
return 0;
}
posted on 2009-07-03 16:41 luis 阅读(216) 评论(0)  编辑 收藏 引用 所属分类: 规律

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2011年2月>
303112345
6789101112
13141516171819
20212223242526
272812345
6789101112

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

文章档案

友情链接

搜索

  •  

最新评论

阅读排行榜

评论排行榜