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 1120. Sum of Sequential Numbers

Why do I get TLE Test#9?
Posted by Илья Гофман (Ilya Gofman) 29 Apr 2004 18:49
subj, actually:(( i can't imagine the test where it doesn't work, tried to decrease eps - nothing better than TLE test #9...


const eps=10e-8;
var  A,N,P:real;
begin
    readln(N);
    A:=1;
    while abs((sqrt(sqr(2*A-1)+8*N))-(trunc(sqrt(sqr(2*A-1)+8*N))))>eps do
      A:=A+1;
    P:=(0.5-A+sqrt(sqr((2*A-1))+8*N)/2);
    writeln(A:0:0,' ',P:0:0);
end

Edited by author 29.04.2004 18:50

Edited by author 29.04.2004 19:06
Did you tried to increase eps?
Posted by Vlad Veselov 29 Apr 2004 18:51
Re: Did you tried to increase eps?
Posted by Илья Гофман (Ilya Gofman) 29 Apr 2004 19:07
I did. Setting eps=10e-5 leads to WA test8, eps=10e-6 and 10e-7 - to WA test 9:(( and then 10e-8 come to TLE:((
Try this
Posted by Andrei Moga 30 Apr 2004 00:28
Re: Try this
Posted by Andrei Moga 30 Apr 2004 00:34
you search for P from the divisors of 2*n less or equal to
sqrt(2*n)
then you verify if A is an integer A=(2*n/P-P+1)/2
you output the first solution because P is maxim(if you begin with sqrt(2*n) and go down)
if you found no A integer you output N 1

              Good Luck!
Re: Try this
Posted by Илья Гофман (Ilya Gofman) 4 May 2004 14:37
thanks! that was the problem! the algorithm was almost the same, but I didn't manage the situation when nothing can be found:((

Edited by author 04.05.2004 15:04