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

Don't you think something is tricky here?
Posted by Lee Junhui Alvin 11 Feb 2002 11:54
Don't you think something is tricky with this question?
If A and P are to be natural numbers, then what is the answer if N=0
Re: Don't you think something is tricky here?
Posted by Lee Junhui Alvin 11 Feb 2002 12:21
> Sorry.....see wrongly.......n > 0 but......how come I can't get AC?

program simple;
var n,a,p,i,n2:longint;
begin
  readln(n);
  a:=0; p:=0; n2:=0;
      inc(a);
      repeat
        n2:=n2+a+p;
        inc(p);
      until n2>=n;
  a:=a+(n2-n);
  p:=p-(n2-n);
  writeln(a,' ',p);
end.
Your program gives wrong answer for n=23
Posted by Tomasz Klos 11 Feb 2002 21:26
Your program writes 6 2
the answer is 11 2