Beauty of a board

5

3 votes
Strategies and Expected values, Dynamic Programming, Algorithms
Problem

There is a N×N board. Rows and columns are numbered from 1 to N. Two persons P1 and P2 randomly select two numbers A and B in between 2 to 2N respectively. They independently paint each block whose sum of row and column numbers is a multiple of their chosen number. The beauty of the board is equal to the number of blocks painted at least once by either one of them. Note that even if they both painted the same block, it only counts once. Print the expected beauty of the board.

Rows and columns are numbered from 1 to N.

Input format

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains an integer N denoting the size of the board.

Output format

For each test case, print the expected beauty of the board in a new line. Print your answer modulo 1e9+7.

Constraints

1T1000001N1000000

It is guaranteed that the sum of N over T test cases does not exceed 1e6.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For the first test case, these person can only choose number 2. Therefore, the expected beauty is 1.

For the second test case, these person can choose any number from {2,3,4}. Thus, the expected beauty for all possible pairs is 23/9.

Editor Image

?