1 / 7
Apr 2007

does someone here find any mistake in my code?
program primes;
uses
crt;
var
i,j,k,t,m,n:integer;
begin
clrscr;
k:=2;
readln(t);
if t<=10 then
begin
for I:=1 to t do
begin
readln(m,n);
if ((m>=1) and (m<=n) and (n<=1000000000) and (n-m<=100000)) then
begin
for J:=m to n do
begin
while (((j mod k) <> 0) and (k<=j)) do
k:=k+1;
if k=j then
writeln(j);
k:=2;
end;
writeln;
end;
end;
end;
end.

  • created

    Apr '07
  • last reply

    Jan '09
  • 6

    replies

  • 1.1k

    views

  • 4

    users

You probably need to take out the "clrscr;". The judge simply compares your program's output with the correct output, and the correct output won't contain whatever clrscr produces.

HTH
S

oh i can't find any mistake in my code too frowning
can someone help me? frowning

var a,b,c,d,e,g,h:int64;
m:array[1..10000]of int64;
begin
m[1]:=2;
b:=2;

for a:=3 to round(sqrt(1000000000)) do
  begin
 for c:=m[1] to m[b-1] do
  if a mod c = 0 then e:=1;
 if e=0 then
   m[b]:=a;
  b:=b+1;
  end;

readln(a);
for b:=1 to a do
begin
readln(c,d);
for e:=c to d do
begin
g:=1;
while m[g] begin
if e mod m[g]=0 then h:=1;
if h=1 then break;
g:=g+1;
end;
h:=0;
end;
end;

end.

Miss, Did you run this? When you put in the sample numbers given in the problem, what answer to do see?

S

i took out 'clrscr' but it still not working. i guess the problem is on their compilator.

The program compiles otherwise you'd see a compilation error as a status.

I think the problem is the size of an integer in free pascal. I don't use free pascal myself, so can't really comment, but when I submitted your program as GPC Pascal, it got TLE. In other words, it ran fine, but took too long.

So I changed integers to longints, and re-submitted as free pascal, and got TLE again.

If possible, it's a good idea to use the same compiler at home as you use on SPOJ. I don't, but then I've also been caught out by similar differences between what I use at home (Delphi) and the Pascal I use on SPOJ (GPC).

So now all you've got to do is figure out how to speed it up!

Good luck!

1 year later

Your code isn't wrong, but it will run slow if input is very big number.