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