Google Kickstart '17 Round A Problem A - Square Counting

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem type

Mr. Panda has recently fallen in love with a new game called Square Off, in which players compete to find as many different squares as possible on an evenly spaced rectangular grid of dots. To find a square, a player must identify four dots that form the vertices of a square. Each side of the square must have the same length, of course, but it does not matter what that length is, and the square does not necessarily need to be aligned with the axes of the grid. The player earns one point for every different square found in this way. Two squares are different if and only if their sets of four dots are different.

Mr. Panda has just been given a grid with R rows and C columns of dots. How many different squares can he find in this grid? Since the number might be very large, please output the answer modulo 10^9+7 (1\,000\,000\,007).

Input Specification

The first line of the input gives T, the number of test cases. T lines follow. Each line has two integers R and C: the number of dots in each row and column of the grid, respectively.

Output Specification

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the number of different squares which can be found in the grid.

Limits

1 \le T \le 100

Subtask 1 [8/25]

2 \le R, C \le 1\,000

Subtask 2 [17/25]

2 \le R, C \le 10^9

Sample Input

4
2 4
3 4
4 4
1000 500

Sample Output

Case #1: 3
Case #2: 10
Case #3: 20
Case #4: 624937395

Explanation

The pictures below illustrate the grids from the first three sample cases, and a valid square in the third sample case.



Creative Commons Attribution 3.0 Unported

Comments

There are no comments at the moment.