zoj 3903 Ant(推公式,逆元)

Ant


Time Limit: 1 Second      Memory Limit: 32768 KB


There is an ant named Alice. Alice likes going hiking very much. Today, she wants to climb a cuboid. The length of cuboid’s longest edge is n, and the other edges are all positive integers. Alice’s starting point is a vertex of this cuboid, and she wants to arrive at the opposite vertex. The opposite vertex means the vertex which has no common planes or edges with the starting point. Just like the picture below:

mtz9548_ant_pic1.gif

Alice is very clever, she always walks on the shortest path. But she can only walk on the surface of the cuboid. Now, Alice only knows the length of cuboid’s longest edge is n, and doesn’t know the length of other edges. Suppose the L is the length of shortest path of a cuboid. Alice wants to compute the sum of L2 for every possible cuboid.

 

Input

The first line of input contains an integer T(T ≤ 100) . is the number of the cases. In the following T lines, there are a positive integer n(1≤n≤1014) in each line. n is the longest edge of the cuboid.

Output

For each test case, output the sum of L2 for every possible cuboid in a line. L is the length of shortest path of a cuboid. It may be very large, so you must output the answer modulo 1000000007.

Sample Input

Sample Output

Hint

(3,2,1) and (3,1,2) are regrad as the same cuboids.

 

 

今天的训练题…

略水?不过这题过地竟然没有一道要写lazy标记的线段树的题过的人数多。

容易知道,最短路径一定是在最长边为单独一边的时候。

设另两条边为a,b

很容易发现(a+b)*(a+b)+n*n <=(n+b)*(n+b)+a*a  打开就看到了。

然后根据勾股定理l2= (a+b)+n2

我们设一共有t个矩阵…

容易发现,关于对角线对称…而对称的两种是算一种的…

正好是三角形数…t=(n+1)*n/2;

将l2= (a+b)+n2  打开得到 l2 = a+ b +2*a*b+n2;

n2一共有t个。

容易发现a2 和b2各有n+1个(画一个表格比较直观

a*b可以先把所有的a*b加在一起,再化简。

 

最后的结果是n*(n+1)/12*(13n2+13n+4)

然后因为要mod 1E9+7。。。又有除法。。所以要用到逆元。

(n*(n-1)/12 )%mod=(12mod-2*n*(n-1))%mod

因为没用逆元wa了一发。。。

然后因为错误地把lld写成 %d…wa了两发。。。

其实这题n有1E14…

o(n)都会跪。。

所以基本差不多是数学+公式。

View Code

 

作者: CrazyKK

ex-ACMer@hust,researcher@sensetime

说点什么

您将是第一位评论人!

提醒
wpDiscuz