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.

来自 <http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3903>

【题意】:

已知一长方体的最大边长 N

求所有可能情况下,两对顶角沿表面的最短距离(展开成平面即可)的平方和。

【解题思路】:

若长方体边长为 N A B,则 L^2 = N^2 + (A+B)^2;

即找出所有小于N的A B组合,求出平方和

例如N=3;则有组合

(1,1)(1,2)(1,3)

(2,2)(2,3)

(3,3)

即最终答案中共有 N(N+1)/2 个 N^2;

再考虑  (A+B)^2 的和:

A取值1~N,对于每个A,B取值为x~n;

将 (A+B)^2展开为 A^2+B^2+2AB 求和

其中平方项每个出现 n+1 次,

而2AB项通过代数可得

将上述项依次求和即可,由于取模原因,除法要先求逆元,这里拓展欧几里得易求。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long
#define mod 1000000007
#define IN freopen("in.txt","r",stdin);
using namespace std; LL x,y,gcd;
void ex_gcd(LL a,LL b)
{
if(!b) {x=;y=;gcd=a;}
else {ex_gcd(b,a%b);LL temp=x;x=y;y=temp-a/b*y;}
} int main(int argc, char const *argv[])
{
//IN; LL two,six;
ex_gcd(, mod);
while(x<) {x+=mod;y-=;}
two = x;
ex_gcd(, mod);
while(x<) {x+=mod;y-=;}
six = x; int t;scanf("%d",&t);
while(t--)
{
LL n, ans = ;
scanf("%lld",&n);n%=mod; ans = (((((n*n)%mod)*((n*(n+))%mod))%mod)*two)%mod;
ans = (ans + ((((((((n+)*n)%mod)*(n+))%mod)*((*n)%mod+))%mod)*six)%mod)%mod;
ans = (ans + ((((n*n)%mod+n)%mod)*(((((n+)*n)%mod)*two)%mod))%mod)%mod;
LL tmp = (((n*(n+))%mod)*two)%mod;
ans = ((ans - ((tmp*tmp)%mod))%mod+mod)%mod; printf("%lld\n", ans%mod);
} return ;
}

ZOJ 3903 Ant(数学,推公示+乘法逆元)的更多相关文章

  1. ZOJ 3903 Ant ZOJ Monthly, October 2015 - A

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

  2. ZOJ 3903 Ant(公式推导)

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

  3. A. On The Way to Lucky Plaza 概率 乘法逆元

    A. On The Way to Lucky Plaza time limit per test 1.0 s memory limit per test 256 MB input standard i ...

  4. 2016中国APP分类排行榜参选入围产品公示

    2016中国APP分类排行榜参选入围产品公示   由中国科学院<互联网周刊>.中国社会科学院信息化研究中心.eNet硅谷动力共同主办的2016中国APP分类排行榜发布暨颁奖晚宴即将举行.此 ...

  5. 一个想法(续五):IT联盟创业计划:现阶段进度公示、疑问解答及进行中的计划

    前言: 首先今天是元宵节,先祝大伙元宵节快,单纯的快乐! 然后看看开展中的计划: IT联盟创业计划众筹发起:一个想法(续三):一份IT技术联盟创业计划书,开启众筹创业征程 IT联盟创业计划众筹进度:一 ...

  6. Luogu T7152 细胞(递推,矩阵乘法,快速幂)

    Luogu T7152 细胞(递推,矩阵乘法,快速幂) Description 小 X 在上完生物课后对细胞的分裂产生了浓厚的兴趣.于是他决定做实验并 观察细胞分裂的规律. 他选取了一种特别的细胞,每 ...

  7. 【2017集美大学1412软工实践_助教博客】团队作业3——需求改进&系统设计 成绩公示

    第三次团队作业成绩公布 题目 团队作业3: 需求改进&系统设计 团队成绩 成绩公示如下: 缩写 TD BZ GJ CJ SI WBS GS JG DB SS SJ CS DC Total 分值 ...

  8. 【软件工程1916|W(福州大学)_助教博客】团队第一次作业成绩公示

    题目 第一次作业 评分准则: 队名(最好能够体现项目内容,要求有亮点与个性):(1分) 拟作的团队项目描述:一句话(中英文不限):(1分) 队员风采:介绍每一名队员,包括成员性格.擅长的技术.编程的兴 ...

  9. 工信部公示网络安全示范项目 网易云易盾“自适应DDoS攻击深度检测和防御系统”入选

    本文由  网易云发布. 工信部官网 2017年年底,经专家评审和遴选,中华人民共和国工业和信息化部(以下简称“工信部”)公示了2017年电信和互联网行业网络安全试点示范项目,网易云易盾的“自适应DDo ...

随机推荐

  1. IOS刷新数据

    在一个项目开发过程中为了更好的体验经常会用到下拉刷新更新数据,当然也伴随一些上拉加载更多数据的情况:当前比较火的EGOTableViewPullRefresh只实现了下拉功能,而没有上拉的功能.这里介 ...

  2. Mongodb查询的用法,备注防止忘记

    最近在用这个东西,为防止忘记,记下来. 集合简单查询方法 mongodb语法:db.collection.find()  //collection就是集合的名称,这个可以自己进行创建. 对比sql语句 ...

  3. [51NOD1126]求递推序列的第n项(矩阵快速幂)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1126 存在参数a,b为负数的情况.这时候要这么处理: 根据mo ...

  4. Akka的Actor模型及使用实例

    本文的绝大部分内容转载自rerun.me这一blog,老外写的东西就是好啊. ACTORS介绍 Anyone who has done multithreading in the past won't ...

  5. hdu2457:DNA repair

    AC自动机+dp.问改变多少个字符能让目标串不含病毒串.即走过多少步不经过病毒串终点.又是同样的问题. #include<cstdio> #include<cstring> # ...

  6. UVa 1149 Bin Packing 【贪心】

    题意:给定n个物品的重量l[i],背包的容量为w,同时要求每个背包最多装两个物品,求至少要多少个背包才能装下所有的物品 和之前做的独木舟上的旅行一样,注意一下格式就好了 #include<ios ...

  7. android通过httpClient请求获取JSON数据并且解析

    使用.net创建一个ashx文件,并response.write  json格式 public void ProcessRequest(HttpContext context) { context.R ...

  8. (转)在mac上配置cocos2d-x开发环境

    转自:http://www.cnblogs.com/xiaodao/archive/2013/01/08/2850751.html 一.下载cocos2d-x最新安装包 在终端中cd到本地将要存放目录 ...

  9. mk文件剖析

    一个Android.mk file用来向编译系统描述你的源代码.具体来说:该文件是GNU Makefile的一小部分,会被编译系统解析一次或多次.你可以在每一个Android.mk file中定义一个 ...

  10. Java [Leetcode 337]House Robber III

    题目描述: The thief has found himself a new place for his thievery again. There is only one entrance to ...