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 n is, and the other edges be all positive integers. Alice ' s starting point was a vertex of this cuboid, and she wants to arrive at the opposite vertex. The opposite vertex means the vertex which have no common planes or edges with the starting point. Just like the picture below:
Alice is very clever, she always walks on the shortest path. But she can only be walk on the surface of the cuboid. Now, Alice only knows the length of Cuboid's longest edge n is, and doesn ' t know the length of other edges. Suppose the is the L length of shortest path of a cuboid. Alice wants to compute the sum of L2 every possible cuboid.
Input
The first line of input contains an integer T(T ≤ 100) . T Is the number of the cases. Tin the following lines, there was a positive integer in each line. is the n(1≤n≤1014) longest edge of the n cuboid.
Output
For each test case, output the sum of L2 every possible cuboid in a line. Is the length of the L shortest path of a Cuboid. It is very large, so you must output the answer modulo 1000000007.
Sample Input
234
Sample Output
160440
Hint
(3,2,1) and (3,1,2) are regrad as the same cuboids.
From <http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3903>
"Test Instructions":
The maximum edge length of a cuboid is known N
For all possible cases, the sum of squares of two recoupling along the surface of the shortest distance (unfolded into a plane).
"Problem-solving ideas":
If the box side length is N A B, then l^2 = n^2 + (a+b) ^2;
That is, finding all A-B combinations less than N , and finding the sum of squares
For example n=3; there is a combination
(1,1) (1,2) (1,3)
(2,2) (2,3)
(3,3)
That is, the final answer is N (n+1)/2 n^2;
Again consider (a+b) the ^2 and:
A takes value 1~n, for each A,B is x~n;
expand (a+b) ^2 to a^2+b^2+2ab sum
Where squared items appear n+1 times each ,
and The 2AB is available through algebra.
The above items can be summed in turn, because of the reason for the modulus, division to seek the inverse of the yuan, where the expansion of Euclid easy to find.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 #defineLL Long Long7 #defineMoD 10000000078 #defineIn Freopen ("In.txt", "R", stdin);9 using namespacestd;Ten One LL x,y,gcd; A voidEX_GCD (LL a,ll b) - { - if(!B) {x=1; y=0; gcd=A;} the Else{EX_GCD (b,a%b); LL temp=x;x=y;y=temp-a/b*y;} - } - - intMainintargcChar Const*argv[]) + { - //in ; + A LL two,six; atEX_GCD (2, MoD); - while(x<0) {x+=mod;y-=2;} -both =x; -EX_GCD (6, MoD); - while(x<0) {x+=mod;y-=6;} -six =x; in - intT;SCANF ("%d",&t); to while(t--) + { -LL N, ans =0; thescanf"%lld", &n); n%=MoD; * $Ans = (((((n*n)%mod) * ((n) (n+1)))%mod))%mod) *two)%MoD;Panax NotoginsengAns = (ans + ((((((((((n+2) (*n)%mod) * (n+1)) * ((%mod) * (2*n)%mod+1))%mod) *six)%mod)%MoD; -Ans = (ans + (((n*n)%mod+n%mod) * (((((n+1) (*n)%mod) *two) (%mod))%mod)%MoD; theLL tmp = (((N (n+1))%mod) *two)%MoD; +Ans = ((Ans-((tmp*tmp)%mod))%mod+mod)%MoD; A theprintf"%lld\n", ans%MoD); + } - $ return 0; $}
ZOJ 3903 Ant (math, push-to-publish + multiply inverse)