ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1209. 1, 10, 100, 1000...

Help for YOU!!!
Posted by Imran Yusubov 10 Aug 2009 16:35
 Take a look at the numbers 11010010001 "1".So we have 1 at
position 1,2,4,7,and so on and because every time one 0 is addesd this numbers increses like sum of the numbers from 1,2,3,4,..+n  +1; so sum of this sequance 1+2+3+...n=n(n+1)/2. And look at our sequence  2+4+7+...n=n(n+1);
And from here you can get this formula (sqrt(8*n-7)-1)/2




Edited by author 10.08.2009 16:54
Re: Help for YOU!!!
Posted by zam_sabina 21 Feb 2010 23:59
Excuse me.. But how could you found out that formula?
Re: Help for YOU!!!
Posted by Yuxin Qin 14 Jun 2012 20:28
Thank you very much!I got AC!
Re: Help for YOU!!!
Posted by Shineon 18 Dec 2012 21:47
Excuse me, but how sum of (1+2+3+...+n) can be less than (2+4+7+...+n)?
Re: Help for YOU!!!
Posted by dima 30 Dec 2012 22:37
Excuse me, but how I can use your formula?
Re: Help for YOU!!!
Posted by Goo 28 Jul 2013 05:42
I have another way to explain this. That's not a correct one, but I got A anyway:
The indexes of the "1" are 1,2,4,7,11,..., which are 1+(0), 1+(1), 1+(1+2), 1+(1+2+3), ... , 1+((k+1)*k/2), ...
Those are "partial sums" of the sequence (1,2,3,4,5,...,k,...)
We have an input index N and we are not sure, if there is some X for which N == 1+((X+1)*X/2).
You'll have to find this X via some arithmetical operations (you can even ignore some numbers in formulas). As if X is an index in the sequence (1,2,3,4,5,...,k,...), you should find out, if it is an Integer number. Too many info, i think.
Re: Help for YOU!!!
Posted by alvaro 13 Aug 2013 07:43
just use this logic
if
(Math.sqrt((8*(num))-7)-1)/2))%1==0
print "1"
else
print "0"

and watch the range of the input ;D
Re: Help for YOU!!!
Posted by MUHAMMAD 3 Apr 2014 23:44
please help me, Me programm 3 test time limit exceeded..
Program is this

package acm.timus.ru;

import java.util.Scanner;

public class N_1209 {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int i=1,a=0,k=0;
    for (int j=1; j<=n; j++) {
       a=sc.nextInt();
       if (i<a) {
           while(i<a){ k++; i+=k; }
       }else{
           while(i>a){ i-=k; k--; }
       }
       if (i==a) { System.out.print("1"+" "); }
       else{System.out.print("0"+" ");}

    }
  }
}
Re: Help for YOU!!!
Posted by lopezio 6 May 2014 21:11
Hi
Here is the correct formula: (sqr(n)+n+2)/2 (for n from 0 to ...)
If one needs I'll explain it.

Edited by author 06.05.2014 21:12
Re: Help for YOU!!!
Posted by Jumabek Alikhanov 21 Oct 2014 08:19
Thank u for your clever explanation!