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:

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

2
3
4

Sample Output

160
440

Hint

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


Author: MU, Tongzhou

题意:就是说给出长方体的长(最长边),问一个蚂蚁从左下角爬到右后上角的所有可能的最短距离的和

解法:

1、听说有人用矩阵乘法过了,蛮厉害的,至今不知怎么推递推式

2、只能傻傻的推公示

显然一个蚂蚁有两种方式到达右后上角

设长为n,令两边为a,b,路程为c

c^2 = n^2+(a+b)^2 = n^2+a^2+b^2+2*a*b

或 c^2 = (n+a)^2+b^2 = n^2+a^2+b^2+2*a*n

显然是上面那个比较小

然后现有如下公式

A = 1+2+3+...+n = (n+1)*n/2

B = 1^2+2^2+3^2+.....+n^2 = n(n+1)(2n+1)/6

C = 1^3+2^3+3^3+......+n^3 = (n*(n+1)/2)^2

然后因为(n,a,b)跟(n,b,a)一样

不妨令a<b

那么(a,b)共有n*(n-1)/2种方式

所以   那个  n^2   总共的和为  n^2*n*(n-1)/2 = n^2*A

观察每种a^2、b^2被加的次数,发现

a^2 的总共的和为   1^2*n+2^2*(n-1)+......+n^2*1  =  sigma(1<=i<=n) i^2*(n-i+1) = sigma(1<=i<=n) (n+1)*i^2-i^3

=   (n+1)*(1^2+2^2+3^2+.....+n^2)-(1^3+2^3+3^3+....+n^3)

= (n+1)*n(n+1)(2n+1)/6- (n*(n+1)/2)^2 = (n+1)*B-C

b^2 的总共的和为    1^2*1+2^2*2+.....+n^2*n =  (n*(n+1)/2)^2 = C

所以a^2+b^2= (n+1)*n(n+1)(2n+1)/6 = (n+1)*B

再观察2*a*b

就是 2*sigma(1<=i<=n) i*(i+(i+1)+.....+n)

= 2*sigma(1<=i<=n) i*(n+i)*(n-i+1)/2

= sigma(1<=i<=n)  i*(n^2-i^2+n+1)

= sigma(1<=i<=n)  n^2*i-i^3+n*i+i

= n^2*A-C+n*A+A

三者相加即可

(公式有可能打错,但思路没错,具体请看代码)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>
using namespace std;
typedef long long LL;
typedef double DB;
#define Rep(i, n) for(int i = (0); i < (n); i++)
#define Repn(i, n) for(int i = (n)-1; i >= 0; i--)
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, t, s) for(int i = (t); i >= (s); i--)
#define rep(i, s, t) for(int i = (s); i < (t); i++)
#define repn(i, s, t) for(int i = (s)-1; i >= (t); i--)
#define MIT (2147483647)
#define MLL (1000000000000000000LL)
#define INF (1000000001)
#define mk make_pair
#define ft first
#define sd second
#define clr(x, y) (memset(x, y, sizeof(x)))
#define sqr(x) ((x)*(x))
#define sz(x) ((int) (x).size())
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
inline void SetIO(string Name) {
string Input = Name+".in", Output = Name+".out";
freopen(Input.c_str(), "r", stdin);
freopen(Output.c_str(), "w", stdout);
} const LL Mod = 1000000007LL;
const int Max = ;
LL n; inline LL GetLL() {
LL Ret = ;
char Ch = ' ';
while(!(Ch >= '' && Ch <= '')) Ch = getchar();
while(Ch >= '' && Ch <= '') {
Ret = Ret*10LL+Ch-'';
Ch = getchar();
}
return Ret;
} inline void Solve(); inline void Input() {
int TestNumber;
scanf("%d", &TestNumber);
while(TestNumber--) {
n = GetLL();
Solve();
}
} inline void Work(LL &m, bool &F2, bool &F3) {
if(!F2 && m% == ) F2 = , m /= ;
if(!F3 && m% == ) F3 = , m /= ;
m %= Mod;
} inline void Solve() {
LL X, Y, Z;
LL A, B, C;
LL m;
bool F2 = , F3 = ; // Get X
F2 = , F3 = , X = ;
m = n;
Work(m, F2, F3);
X = (X*m)%Mod; m = (n+);
Work(m, F2, F3);
X = (X*m)%Mod; m = (*n+);
Work(m, F2, F3);
X = (X*m)%Mod; // Get Y
F2 = , F3 = , Y = ;
m = n;
Work(m, F2, F3);
Y = (Y*m)%Mod; m = n+;
Work(m, F2, F3);
Y = (Y*m)%Mod; Y = (Y*Y)%Mod; // Get Z
F2 = , F3 = , Z = ;
m = n;
Work(m, F2, F3);
Z = (Z*m)%Mod; m = n+;
Work(m, F2, F3);
Z = (Z*m)%Mod; m = n%Mod;
// Get A
A = Z;
A = (A*m)%Mod;
A = (A*m)%Mod; // Get B
B = X;
B = (B*(m+))%Mod; // Get C
C = (((m*m)%Mod)*Z)%Mod;
C = (C-Y+Mod)%Mod;
C = (C+X)%Mod;
C = (C+((m*Z)%Mod))%Mod; LL Ans = (A+B+C)%Mod;
cout<<Ans<<endl;
} int main() {
Input();
//Solve();
return ;
}

ZOJ 3903 Ant ZOJ Monthly, October 2015 - A的更多相关文章

  1. ZOJ 3913 Bob wants to pour water ZOJ Monthly, October 2015 - H

    Bob wants to pour water Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge There i ...

  2. ZOJ 3911 Prime Query ZOJ Monthly, October 2015 - I

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  3. ZOJ 3910 Market ZOJ Monthly, October 2015 - H

    Market Time Limit: 2 Seconds      Memory Limit: 65536 KB There's a fruit market in Byteland. The sal ...

  4. ZOJ 3908 Number Game ZOJ Monthly, October 2015 - F

    Number Game Time Limit: 2 Seconds      Memory Limit: 65536 KB The bored Bob is playing a number game ...

  5. ZOJ 3905 Cake ZOJ Monthly, October 2015 - C

    Cake Time Limit: 4 Seconds      Memory Limit: 65536 KB Alice and Bob like eating cake very much. One ...

  6. 143 - ZOJ Monthly, October 2015 I Prime Query 线段树

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  7. ZOJ 3903 Ant(数学,推公示+乘法逆元)

    Ant Time Limit: 1 Second      Memory Limit: 32768 KB There is an ant named Alice. Alice likes going ...

  8. ZOJ 3903 Ant(公式推导)

    这个公式推导过程是看的这位大牛的http://blog.csdn.net/bigbigship/article/details/49123643 扩展欧几里德求模的逆元方法: #include < ...

  9. 思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys

    题目传送门 /* 题意:n个时刻点,m次时光穿梭,告诉的起点和终点,q次询问,每次询问t时刻t之前有多少时刻点是可以通过两种不同的路径到达 思维:对于当前p时间,从现在到未来穿越到过去的是有效的值,排 ...

随机推荐

  1. HDU 1062 Text Reverse(水题,字符串处理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符. #include< ...

  2. [Effective JavaScript 笔记]第59条:避免过度的强制转换

    js是弱类型语言.许多标准的操作符和代码库会把输入参数强制转换为期望的类型而不是抛出错误.如果未提供额外的逻辑,使用内置操作符的程序会继承这样的强制转换行为. functin square(x){ r ...

  3. 学号160809212姓名田京诚C语言程序设计实验2选择结构程序设计

    编写一个C程序,输入3个数,并按由大到小的顺序输出. 1 #include <stdio.h> void main(){ int a,b,c,t; printf("请输入三个整数 ...

  4. 一个csrf实例漏洞挖掘带你了解什么是csrf

    [-]CSRF是个什么鬼? |___简单的理解: |----攻击者盗用了你的身份,以你的名义进行某些非法操作.CSRF能够使用你的账户发送邮件,获取你的敏感信息,甚至盗走你的财产. |___CSRF攻 ...

  5. 图像特征提取:Sobel边缘检测

    前言 点和线是做图像分析时两个最重要的特征,而线条往往反映了物体的轮廓,对图像中边缘线的检测是图像分割与特征提取的基础.文章主要讨论两个实际工程中常用的边缘检测算法:Sobel边缘检测和Canny边缘 ...

  6. SIFT+HOG+鲁棒统计+RANSAC

    今天的计算机视觉课老师讲了不少内容,不过都是大概讲了下,我先记录下,细讲等以后再补充. SIFT特征: 尺度不变性:用不同参数的高斯函数作用于图像(相当于对图像进行模糊,得到不同尺度的图像),用得到的 ...

  7. 代码风格与树形DP

    Streaming很惨,不过因为比赛之间没有提交过就没掉(或掉了)rating.第二题是一个树形DP,但是我都在想第一题了,简直作死. 看着神犇的代码我也是醉了...各种宏,真是好好写会死系列. 看到 ...

  8. php自定义函数call_user_func和call_user_func_array详解

    看UCenter的时候有一个函数call_user_func,百思不得其解,因为我以为是自己定义的函数,结果到处都找不到,后来百度了一下才知道call_user_func是内置函 call_user_ ...

  9. 【OpenStack】OpenStack系列14之Dashboard定制开发

    django概述 参考资料:http://blog.javachen.com/2014/01/11/how-to-create-a-django-site.html http://djangobook ...

  10. Android 中PendingIntent---附带解决AlarmManager重复加入问题

    最近在程序中使用到了notification功能,自然,就涉及到了PendingIntent,下面总结下. 1 什么是PendingIntent A description of an Intent ...