Timus 1209. 1, 10,100,100 0...

Source: Internet
Author: User
Document directory
  • Input
  • Output
  • Sample
Timus 1209. 1, 10,100,100 0... requires that the value at the specified position of a specific sequence be given.

1209. 1, 10,100,100 0... time limit: 1.0 second
Memory limit: 16 mblet's consider an infinite sequence of digits constructed of ascending powers of 10 written one after another. Here is the beginning of the sequence: 110100100010000... You are to find out what digit is located at the definite position of the sequence. inputthere is the only positive integer number NIn the first line, N& Lt; 65536. I-Th NLeft lines contains the positive integer Ki-The number of positions in the sequence. It's given that Ki<231. outputyou are to output NDigits 0 or 1 separated with a space. More precisely, I-Th digit of output is to be equal to Ki-Th digit of described above sequence. Sample
Input Output
4
3
14
7
6
0 0 1 0

Problem Author:Alexey lakhtin
Problem Source:USU open Collegiate Programming Contest October '2002 Junior session

This question is, let's consider an infinite sequence consisting of 10 non-negative integer power connections in turn: 110100100010000 .... Your task is to give the value of the specified position of the sequence.

Through careful observation, we can see that the first 1 in the sequence (x + 1) is located in the nth = 1 + (1 + 2 +... x) = 1 + x (x + 1)/2 positions. Solve the quadratic equation of x and obtain the non-negative root of X = (√ 8n-7-1)/2. Therefore, when X is an integer, the value of the nth position in the sequence is 1, and the value of other positions is 0.

The corresponding C # program is as follows:

1 using system;
2
3 // http://acm.timus.ru/problem.aspx? Space = 1 & num = 1209
4 class t1209
5 {
6 static void main ()
7 {
8 For (INT I = int. parse (console. Readline (); I> 0; I --)
9 {
10 double X = (math. SQRT (8.0 * Int. parse (console. Readline ()-7)-1)/2;
11 console. Write (x = (INT) x )? 1: 0) + "");
12}
13}
14} Returned directory

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.