Infinite sequence of Tyvj-tom

Source: Internet
Author: User

Background of the simulation questions of Sichuan College Tom has an infinite sequence as follows:
110100100010000100000 .....
Please help Tom find the number in the specified position in this infinite sequence the first line of a positive integer n indicates the number of queries;
The next n line is a positive integer ai,ai that represents the position in the sequence. The output format is n lines, with each behavior 0 or 1, representing the number on the AI bit of the sequence. Test Sample 1 input
4
3
14
7
6
Output
0
0
1
0
Note There are n<=1500000,ai<=10^9 for 100% of the data
Tip: Arithmetic progression Sn (top N and) =n (n+1)/2 with a difference of 1
Moe-ing idea: This data is a bit large, do not consider the whole sequence of simulation to seek, you can find the law of the sequence, in its calculation. Process: Can first for the a-1+0.25, and take the whole, and then use a-sum* (sum-1)/2, so you can know that one is not 1 or 0. The code is as follows:
1#include <stdio.h>2#include <math.h>3 intMain ()4 {5     intA,sum,n;6scanf"%d",&n);7      while(n--)8     {9scanf"%d",&a);Tensum=0.5+SQRT (0.25+2* (A-1));//for the a-1+0.25, and take the whole Onea=a-sum* (sum-1)/2; A         if(a==1) printf ("%d\n",1);//is 1 -         Elseprintf"%d\n",0);//otherwise it's 0 . -     } the     return 0; -}

Infinite sequence of Tyvj-tom

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.