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...

Why my solution is wrong? I just use binary search.
Posted by Vlad Veselov 26 Jun 2003 13:55
  Program Task1209; { Binary Search }
   Var L,R,Num,N,I : Word;
       K,T         : LongInt;

   Function F(Const A : LongInt) : LongInt;
    Begin
     F := A * (A + 1) Shr 1;
    End;

   BEGIN
    ReadLn(N);
    For I := 1 To N Do
     begin
      ReadLn(K);
      If K = 1
       Then Write('1 ')
       Else begin
             L := 1;
             R := 40000;
             While R - L <> 1 Do
              begin
               Num := (R + L) Shr 1;
               T := F( Num );
               If K > T
                Then L := Num
                Else R := Num;
              end;
             Num := (R + L) Shr 1;
             T := K - F( Num );
             If T = 1
              Then Write('1 ')
              Else Write('0 ');
            end;
     end;
   END.