if you declare your array 5000 that means the index is between 0-4999.
if the input is 5000 then your code try to read index 5000 which is illegal.
i think thats why you got RTE.
i don't understand, simply don't understand.
i print 5000 and it seems right.
who can test it for me?
just sumbit to the online judge.
and may know what problem i may occur.
Using write to produce output in pascal is extremely slow. Assemble all output for one line in an ansistring and do one writeln.
Change
[pascal] for n := k downto 1 do
write(ans[i,n]);
writeln;[/pascal]
To
[pascal] setlength(line,k);
for n := k downto 1 do
line[k-n+1]:=chr(ans[i,n]+ord('0'));
writeln(line); [/pascal]
where var line:ansistring;
That way you'll get AC in less than a second!
PS: please remove your code now, 'cause it's a spoiler
i don't understand why my program is wrong
please give any comments ....
how about the output format for a very big number (with exponential ?)
[pascal]
program p495 (input, output);
var
n,j :integer;
x,y,z,temp:extended;
begin
while not eof(input) do begin
readln(n);
x:=1;
y:=1;
if n=0 then z:=0 else z:=1;
for j:=3 to n do begin
z:=x+y;
temp:=y;
y:=z;
x:=temp;
end;
writeln('The Fibonacci number for ',n,' is ',z:0:0);
end;
end.
[/pascal]
First look at the previous posts before starting a new thread!
It is somewhere stated that the 5000th fibo has more than 1000 digits, your program doesn't even come close.
the name of problem the Fibonacci Freeze . So you have to freeae/store it. becasue for 5000th fib u need to genarate upto 4999'th and so on. So there is repeating. What will be the conditon if 5000 have 100 times in judge input. No doubt that it will cause TLE