比赛 |
2016-10-11 4 syz |
评测结果 |
AAAAAAAAAA |
题目名称 |
无穷的序列 |
最终得分 |
100 |
用户昵称 |
安呐一条小咸鱼。 |
运行时间 |
0.314 s |
代码语言 |
C++ |
内存使用 |
0.31 MiB |
提交时间 |
2016-10-11 19:22:13 |
显示代码纯文本
- #include<algorithm>
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<cmath>
- using namespace std;
- long long n,x;
- int main(){
- /*
- 因为1出现的位置为 1 2 4 7 11...
- 很明显的可以看出位置的通项为 n*(n-1)/2 + 1;
- 那么假设一个位置 上的数为t
- 则 n*(n-1)/2 + 1 = t;
- 同乘 2
- n*(n-1)+2 = n^2 - n + 2 = 2t
- ( n - 1/2 )^2 = 2t - 7/4
- 同乘 4
- (2n-1)^2 = 8t-7
- 所以只用判断8t-7是否为平方数23333!
- */
- freopen("unlessseq.in","r",stdin);
- freopen("unlessseq.out","w",stdout);
- scanf("%lld",&n);
- for(long long i=1;i<=n;i++)
- {
- scanf("%lld",&x);
- x=x*8-7;
- long long t=ceil(sqrt(x));
- if( t*t ==x )
- {
- puts("1");
- }
- else puts("0");
- }
- return 0;
- }