how it's possible that this code spend 320kb of memory?
program factor;
const
F7=string('5040');
F8=string('40320');
F9=string('362880');
F10=string('3628800');
F11=string('39916800');
F12=string('479001600');
F13=string('6227020800');
sOver=('Overflow!');
sUndr=('Underflow!');
var
dato:longInt;
begin
readln(dato);
while (not eof(input)) do
begin
readln(dato);
if dato<0 then begin
if dato mod 2 = 0 then writeln(sUndr) else writeLn(sOver) end
else begin
case dato of
0..6: writeLn(sUndr);
7: writeLn(F7);
8: writeLn(F8);
9: writeLn(F9);
10: writeLn(F10);
11: writeLn(F11);
12: writeLn(F12);
13: writeLn(F13);
else writeLn(sOver);
end; end;
end;
end.
I really don't understand that a 36 lines program with a single variable can be so memory greedy
why so much mem?
Moderator: Board moderators
As far as I have figured it out, it has to do something with internal IO buffering. Not sure about it though.
Ivor
Ivor
There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
-
- New poster
- Posts: 8
- Joined: Wed Sep 18, 2002 2:10 am
Probably you'r right. But as anyhow I realize that the same algorithm in C++ is much faster than in Pascal. The problem 264 (Count on Cantor) in Pascal uses 324kb of memory and 0.130 s. of CPU time, while in C++ the figures are 64kb for memory and 0.010 s. of time.
All that despite I don't know C or C++, appart from the basics.
All that despite I don't know C or C++, appart from the basics.
Are you sure the algorithm you used is exactly the same?
I have noticed that Pascals IO is too slow -- C, C++ can almost always beat it. But I have also noticed that pascals floating point functions are slighly faster that that of C. That was true for gnu pascal, don't know about freepascal. I just noticed it when I was looking through ranklists.
Ivor
I have noticed that Pascals IO is too slow -- C, C++ can almost always beat it. But I have also noticed that pascals floating point functions are slighly faster that that of C. That was true for gnu pascal, don't know about freepascal. I just noticed it when I was looking through ranklists.
Ivor
There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.