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 109 + 7 (1000000007).
The first line of the input gives the number of test cases, T. T lines follow. Each line has two integers R and C: the number of dots in each row and column of the grid, respectively.
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 can be found in the grid.
1 ≤ T ≤ 100.
2 ≤ R ≤ 1000. 2 ≤ C ≤ 1000.
2 ≤ R ≤ 109. 2 ≤ C ≤ 109.
第一次做 Kickstart 就被狠狠地打脸:cry: 。很水的题目,But,太天真。对 Python 不熟悉导致各种问题频发。
公式:
但是,对于大数据,一眼就可以看到即使是 long long
也无法进行表示。写大整数过于繁杂,比赛时又没有仔细去化简,故而选择了 Python (:laughing: 之后就被精度问题彻底打爆)。由于 Python 的整型可以自动支持大整数,也不用专门去化简之类的。
重点是: 用 C/C++ 都会很注意 double
对精度的影响,但是,对于 Python 来说,其弱类型就导致了当声明 1e9+7
的时候,默认会作为浮点数,若不注意强转数据类型,float
对最终的大整数取模将产生致命的错误。
新闻热点
疑难解答