# 棋盘（数学趣味题） - HDU 5100

Problem Description

Consider the problem of tiling an n×n chessboard by polyomino pieces that are k×1 in size; Every one of the k pieces of each polyomino tile must align exactly with one of the chessboard squares. Your task is to figure out the maximum number of chessboard squares tiled.

Input

There are multiple test cases in the input file.

First line contain the number of cases T (T≤10000).

In the next T lines contain T cases , Each case has two integers n and k. (1≤n,k≤100)

Output

Print the maximum number of chessboard squares tiled.

Sample Input

2

6 3

5 3

Sample Output

36

24

1. 先横着摆放，然后用竖着的补全，剩下的是一个边长为n%k的正方形
2. 在一个角摆成风车形（边长k+n%k），中间形成边长为k-n%k的正方形

（方法1 先横着后竖着）

（方法2 摆成风车型）

```#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
int test_count;
scanf("%d", &test_count);

while (test_count--)
{
int n, k;
scanf("%d%d", &n, &k);

if (k > n)
puts("0");
else {
if (n % k == 0)
printf("%d\n", n * n);
else {
//两种摆法取边小的
//1、横着摆放竖着补全，形成边长n%k的正方形
//2、在一个角摆成风车形（边长k+n%k），中间形成边长为k-n%k的正方形
int m = min(n % k, k - n % k);
printf("%d\n", n * n - m*m);
}
}
}
return 0;
}```

212 篇文章32 人订阅

0 条评论

## 相关文章

1163

3021

6544

### 【大牛经验】26种语言输出HelloWord

【大牛】26种语言输出HelloWord 1. C ? ---- 2. C++ ? ---- 3. C# ? ---- 4. Bash echo "Hello,...

3968

2000

3504

2319

1185

37811

853