ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1024. Permutations

WA!!!
Posted by Inzaghi 19 Sep 2003 19:29
var i,j,k,n,m,l:longint;
    a:array[1..10000]of longint;
    p:boolean;
begin
     readln(n);
     for i:=1 to n do
     begin
          read(k);
          if k>i then k:=k-i
                 else k:=i-k;
          if k=0 then continue;
          p:=false;l:=k;
          for j:=2 to trunc(sqrt(l)) do
          begin
               m:=0;
               repeat
                     if k mod j=0 then begin inc(m);k:=k div
j;p:=true;end
                                  else break;
                     if k=0 then break;
               until false;
               if m>a[j] then a[j]:=m;
          end;
          if (p=false)and(a[k]=0) then a[k]:=1;
     end;
     k:=1;
     for i:=2 to 1000 do if a[i]>0 then
         for j:=1 to a[i] do k:=k*i;
     writeln(k);
end.