Gym 101981G - Pyramid - [打表找规律][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem G]
题目链接:http://codeforces.com/gym/101981/attachments
The use of the triangle in the New Age practices seems to be very important as it represents the unholy
trinity (Satan, the Antichrist and the False Prophet bringing mankind to the New World Order with
false/distorted beliefs). The triangle is of primary importance in all Illuminati realms, whether in the
ritual ceremonies of the Rosicrucians and Masons or the witchcraft, astrological and black magic practices
of other Illuminati followers.
One day you found a class of mysterious patterns. The patterns can be classified into different degrees. A
pattern of degree n consists of n*(n+1)/2 small regular triangles with side length 1, all in the same direction,
forming a big triangle. The figure below shows the pattern of degree 3. All small regular triangles are
highlighted.

Since the pattern contains many regular triangles, which is very evil and unacceptable, you want to
calculate the number of regular triangles formed by vertices in the pattern, so that you can estimate the
strength of Illuminati. It is not necessary that each side of regular triangles is parallel to one side of the
triangles. The figure below shows two regular triangles formed by vertices in a pattern of degree 3.

Since the answer can be very large, you only need to calculate the number modulo 10^9 + 7.
Input
The first line contains an integer t (1 ≤ t ≤ 10^6) — the number of test cases.
Each of the next t lines contains an integer n (1 ≤ n ≤ 10^9) — the degree of the pattern.
Output
For each test case, print an integer in one line — the number of regular triangles modulo 10^9 + 7.
Example
standard input
3
1
2
3
standard output
1
5
15
题意:
上面那个图形的度数为 $3$,里面包含了 $15$ 个正三角形。现在给出度数 $n$,让你找出那样一个图形里面包含多少个正三角形。
题解:
暴力打出度数在 $1 \sim 20$ 内的表,发现规律是三阶差分是等差数列 $4,5,6,7,\cdots$(真的我没有开玩笑……),或者说四阶差分是常数 $1$。然后果断推了个递推式用矩阵快速幂交了一发……TLE+1。
然后知道了只能 $O(1)$ 地求,开始考虑推通项公式。类比于四次函数求四阶导数之后为常数,换句话说通向公式应当是一个四次多项式。
因此可以假设 $a_n = An^4 + Bn^3 + Cn^2 + Dn + E$,然后将前五项 $a_1 = 1, a_2 = 5, a_3 = 15, a_4 = 35, a_5 = 70$ 代入解五元一次线性方程组,
解得 $A = \frac{1}{24}, B = \frac{1}{4}, C = \frac{11}{24}, D = \frac{1}{4}, E = 0$。
(注意不要忘了除法是乘逆元……已经有两次因为这个WA+n了……)
然后实际上,OEIS搜一下就可以知道 $a_n = C_{n+3}^{4}$。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+;
ll n;
ll fpow(ll a,ll n)
{
ll res=,base=a%mod;
while(n)
{
if(n&) res*=base, res%=mod;
base*=base, base%=mod;
n>>=;
}
return res%mod;
}
ll inv(ll a){return fpow(a,mod-);}
int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%I64d",&n);
ll ans=;
ans+=fpow(n,), ans%=mod;
ans+=*fpow(n,)%mod, ans%=mod;
ans+=*fpow(n,)%mod, ans%=mod;
ans+=*n%mod, ans%=mod;
ans*=inv(), ans%=mod;
printf("%I64d\n",ans);
}
}
Gym 101981G - Pyramid - [打表找规律][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem G]的更多相关文章
- Gym 101981J - Prime Game - [数学题][线性筛+分解质因数][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem J]
题目链接:http://codeforces.com/gym/101981/attachments 题意: 令 $mul(l,r) = \prod_{i=l}^{r}a_i$,且 $fac(l,r)$ ...
- 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛
Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...
- Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律
题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...
- 最短路+找规律 Samara University ACM ICPC 2016-2017 Quarterfinal Qualification Contest L. Right Build
题目链接:http://codeforces.com/gym/101149/problem/L 题目大意:有n个点(其实是n+1个点,因为编号是0~n),m条有向边.起点是0,到a和b两个节点,所经过 ...
- Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP
题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...
- Gym - 101981D The 2018 ICPC Asia Nanjing Regional Contest D.Country Meow 最小球覆盖
题面 题意:给你100个三维空间里的点,让你求一个点,使得他到所有点距离最大的值最小,也就是让你找一个最小的球覆盖掉这n个点 题解:红书模板题,这题也因为数据小,精度也不高,所以也可以用随机算法,模拟 ...
- Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机
题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...
- Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流
题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...
- Gym - 101981J The 2018 ICPC Asia Nanjing Regional Contest J.Prime Game 计数
题面 题意:1e6的数组(1<a[i]<1e6), mul (l,r) =l × (l+1) ×...× r, fac(l,r) 代表 mul(l,r) 中不同素因子的个数,求s ...
随机推荐
- 微信SDK登录无法调起,微信SDK无法接收回调的几种解决办法
今天有位同事请求帮忙调试微信登录问题,他遇到了以下2个问题,所以,写篇日志备忘,如果有其它朋友遇到此类问题,都可以照此解决! 平时在开发中,有些开发者经常会遇到微信登录SDK登录时,无法调起微信客户端 ...
- Asp.net的HttpContext.Current.Items详解
之前asp.net只是在使用Session来进行用户会话时的信息存储,甚至很少留意Session完整的类调用是HttpContext.Current.Sessoin.... 好吧,我还是处于只会固定写 ...
- 理解 CI 和 CD 之间的区别(翻译)
博客搬迁至https://blog.wangjiegulu.com RSS订阅:https://blog.wangjiegulu.com/feed.xml 原文链接:https://blog.wang ...
- 使用protobuf编译onnx.proto过程中的一些问题总结
使用git clone下载protobuf的源代码,然后git checkout到branch2.7.0: 编译protobuf,先在代码顶层目录执行./configure,然后执行make,成功后执 ...
- linux 修改图片的尺寸
# convert -sample 50.png .png #把512*512的图片修改为500*500的图片 # which convert /usr/bin/convert # rpm -qf / ...
- NameError:name ‘xrange’ is not defined
运行某代码时,报错: NameError:name 'xrange' is not defined 原因: 在Python 3中,range()与xrange()合并为range( ).我的pytho ...
- 【转载 Hadoop&Spark 动手实践 2】Hadoop2.7.3 HDFS理论与动手实践
简介 HDFS(Hadoop Distributed File System )Hadoop分布式文件系统.是根据google发表的论文翻版的.论文为GFS(Google File System)Go ...
- 【Unity】UGUI聊天消息气泡 随文本内容自适应
游戏中需要用做UGUI做聊天界面.其中聊天气泡ChatItem的UI要求能随着聊天内容文本的长度自适应的. 网上搜了一下聊天气泡的UI,发现都不太符合咱的需求,具体来说是文本宽度不足一行时,文本宽度自 ...
- go语言字符串的连接和截取
字符串的连接: https://studygolang.com/articles/12281?fr=sidebar 字符串的截取: https://studygolang.com/articles/9 ...
- Deepin 系统下安装VMware并激活
1.打开深度商店:搜索VMware,并下载安装. 2.打开启动器:点击VMware-install. 3.填写管理员密码. 4.下一步,完成安装. 5.打开VMware Workstation,输入密 ...