Programming contests

50 Programming Exercise for Beginners

January 2, 2019 12:00 AM – December 31, 2019 12:00 AM

Farmer

Yim has always wanted to be a farmer. After his computer engineering graduation, he went straight back to his home and prepared to do a hydroponic farm. However, he has a problem. The plants he is growing are of different size, but they are all square-shaped, for example 1 × 1, 2 × 2, or 3 × 3. The greenhouse he is using for the plants is shaped like a rectangle. Write a program to find the total number of squares of each size that can be fitted in the greenhouse, as well as the total area of all these squares.

Input Specification

The first line of the input contains n (0 < n ≤ 100), the number of test cases. Then n lines follow, each containing one test case. Each test case has two integers: w (0 < w ≤ 1000) and h (0 < h ≤ 1000), separated by a space, describing the width and height of the greenhouse.

Output Specification

For each test case, output in a line two numbers separated by a space. The first number is the total number of squares of each size that can be fitted in the greenhouse, and the second number is the total area of all these squares.

Sample Input

  1. 4
  2. 1 1
  3. 3 2
  4. 3 3
  5. 4 3
download as text file

Output for Sample Input

  1. 1 1
  2. 8 14
  3. 14 34
  4. 20 54
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019