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:

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) . T 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(数学,推公示+乘法逆元)的更多相关文章
- 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 ...
- ZOJ 3903 Ant(公式推导)
这个公式推导过程是看的这位大牛的http://blog.csdn.net/bigbigship/article/details/49123643 扩展欧几里德求模的逆元方法: #include < ...
- 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 ...
- 2016中国APP分类排行榜参选入围产品公示
2016中国APP分类排行榜参选入围产品公示 由中国科学院<互联网周刊>.中国社会科学院信息化研究中心.eNet硅谷动力共同主办的2016中国APP分类排行榜发布暨颁奖晚宴即将举行.此 ...
- 一个想法(续五):IT联盟创业计划:现阶段进度公示、疑问解答及进行中的计划
前言: 首先今天是元宵节,先祝大伙元宵节快,单纯的快乐! 然后看看开展中的计划: IT联盟创业计划众筹发起:一个想法(续三):一份IT技术联盟创业计划书,开启众筹创业征程 IT联盟创业计划众筹进度:一 ...
- Luogu T7152 细胞(递推,矩阵乘法,快速幂)
Luogu T7152 细胞(递推,矩阵乘法,快速幂) Description 小 X 在上完生物课后对细胞的分裂产生了浓厚的兴趣.于是他决定做实验并 观察细胞分裂的规律. 他选取了一种特别的细胞,每 ...
- 【2017集美大学1412软工实践_助教博客】团队作业3——需求改进&系统设计 成绩公示
第三次团队作业成绩公布 题目 团队作业3: 需求改进&系统设计 团队成绩 成绩公示如下: 缩写 TD BZ GJ CJ SI WBS GS JG DB SS SJ CS DC Total 分值 ...
- 【软件工程1916|W(福州大学)_助教博客】团队第一次作业成绩公示
题目 第一次作业 评分准则: 队名(最好能够体现项目内容,要求有亮点与个性):(1分) 拟作的团队项目描述:一句话(中英文不限):(1分) 队员风采:介绍每一名队员,包括成员性格.擅长的技术.编程的兴 ...
- 工信部公示网络安全示范项目 网易云易盾“自适应DDoS攻击深度检测和防御系统”入选
本文由 网易云发布. 工信部官网 2017年年底,经专家评审和遴选,中华人民共和国工业和信息化部(以下简称“工信部”)公示了2017年电信和互联网行业网络安全试点示范项目,网易云易盾的“自适应DDo ...
随机推荐
- 网站常见问题及解决方法(div/css)
18.<a> 在IE6,7 下面重新定义宽和高的代码:{ display:block; display:-moz-inline-stack; display:inline-block; ...
- windows 下 apache设置
apache,apache配置,配置端口 mac下apache配置 添加虚拟主机: Alias /selftest/ "D:/self-test/" <Directory & ...
- 【Todo】JS跨域访问问题的解决
做双十一,需要在主会场页面,嵌入我们产品的JS豆腐块.而这个豆腐块需要调用我们后端的数据接口,涉及跨域访问. 参考 http://www.cnblogs.com/2050/p/3191744.html ...
- Struts2系列——struts2的result
在action的指定方法执行完毕后总会返回一个字符串,struts2根据返回的字符串去action的配置中的result去找匹配的名字,根据配置执行下一步的操作. 在ActionSupport基类中定 ...
- I.MX6 git patch
/********************************************************************** * I.MX6 git patch * 说明: * 之前 ...
- Android PRODUCT_COPY_FILES 自动拷贝文件
/********************************************************************** * Android PRODUCT_COPY_FILES ...
- UVA 1151 Buy or Build (MST最小生成树,kruscal,变形)
题意: 要使n个点之间能够互通,要使两点直接互通需要耗费它们之间的欧几里得距离的平方大小的花费,这说明每两个点都可以使其互通.接着有q个套餐可以选,一旦选了这些套餐,他们所包含的点自动就连起来了,所需 ...
- 【 D3.js 高级系列 — 10.0 】 思维导图
思维导图的节点具有层级关系和隶属关系,很像枝叶从树干伸展开来的形状.在前面讲解布局的时候,提到有五个布局是由层级布局扩展来的,其中的树状图(tree layout)和集群图(cluster layou ...
- BUFFER CACHE之主要的等待事件
原因:资源紧张,等待其释放. 原因的原因:1. lgwr和DBWn进程写太慢:2. Buffer和latch不可用 原因的原因的原因:全表扫描.library cache latches数太多等. 视 ...
- Delphi EVariantTypeCastError错误的解决方法
在执行程序的时候总是提示: ---------------------------Debugger Exception Notification---------------------------P ...