Cod sursa(job #763848)
Program curcubeu;
var a,b,c,d,e:array [1..1000001] of longint;
i,j,n,aux:longint;
fi,fo:text;
begin
assign(fi,'curcubeu.in');
assign(fo,'curcubeu.out');
reset(fi); rewrite(fo); readln(fi,n,a[1],b[1],c[1]); d[1]:=1;
for i:=2 to n-1 do begin
a[i]:=(a[i-1]*i) mod n;
b[i]:=(b[i-1]*i) mod n;
c[i]:=(c[i-1]*i) mod n;
d[i]:=i;
if a[i]>b[i] then begin aux:=a[i]; a[i]:=b[i]; b[i]:=aux; end;
end;
for i:=n-1 downto 1 do begin
j:=a[i];
while j<=b[i] do begin
if e[j]=0 then e[j]:=c[i];
j:=d[j]+1;
end;
d[a[i]]:=d[b[i]];
end;
for i:=1 to n-1 do writeln(fo,e[i]);
close(fo);
end.