views:

20

answers:

0

I'm working in Pascal, I don't understand why I'm getting a NZEC error when I'm submitting my problem. On my pc it works perfectly. Can you give my your opinion please?

program super_factor_sum;
var k,i,j,s:longint;   f,g:text;

function prim(x:integer):boolean; var d:longint;
begin
prim:=true;
for d:=2 to x div 2 do if x mod d=0 then prim:=false;
end;

begin assign(f,'input.txt'); reset(f); assign(g,'output.txt'); rewrite(g);
while not eof(f) do
begin readln(f,k);  s:=0;  i:=2;
      while (k<>1) or (i<=k) do
            begin if (prim(i)) and (k mod i=0) then
                       begin j:=0;
                             repeat k:=k div i; j:=j+1;
                             until k mod i<>0;
                             s:=s+i*j; i:=i+1;
                       end
                             else i:=i+1;
            end;
      write(s);   writeln(g,s);
end;
close(f);  close(g);
end.