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

Pleasy help me! I have CE!
Posted by волчонок 7 Jul 2005 22:46
 My program works well, but it got CE!
 Please tell me where is my mistake.

 Here is my program:

var n,i,j,kol,res:integer;
    a,p:array [1..1000] of integer;
    b:array [1..1000] of boolean;


Procedure init;
 Begin
  fillchar(b,sizeof(b),false);
   readln(n);
   for i:=1 to n do read(a[i]);
End;


Function min(x,y:longint):longint;
 Begin
  if x<y then min:=x else min:=y
End;


Function max(x,y:longint):longint;
 Begin
  if x>y then max:=x else max:=y
End;


Function NOK_(x,y:longint):longint;
 Begin
  NOK_:=1;
   if x mod y=0 then NOK_:=x else

    Begin
     for i:=2 to y do
      if (x mod i=0) and (y mod i=0) then
        begin
         NOK_:=NOK_*i;
         x:=x div i;
         y:=y div i;
        end;
      NOK_:=NOK_*x*y;
    End;
End;


Procedure main;
 Begin

 For i:=1 to n do
  if not b[i] then Begin
   j:=i; kol:=0;

   repeat
    j:=a[j];
    b[j]:=true;
    kol:=kol+1;
   until j=i;

   for j:=1 to n do
    if b[j] and (p[j]=0) then p[j]:=kol;

  End;

   res:=p[1];
   for i:=2 to n do res:=NOK_(max(res,p[i]),min(res,p[i]));

End;


Procedure out;
 Begin
  write(res);
End;


BEGIN

 init;  main;  out;

END.
Re: Pleasy help me! I have CE!
Posted by Kit 7 Jul 2005 23:26
Vladimir Yakovlev said "See F.A.Q.". There are said about option "Reply to my E-Mail address".

Edited by author 07.07.2005 23:27
Re: Pleasy help me! I have CE!
I've change the function NOK_:

Function NOK_(x,y:longint):longint;
Var tmp : longint;
Begin
tmp:=1;
if x mod y=0 then tmp:=x else
Begin
for i:=2 to y do
if (x mod i=0) and (y mod i=0) then
begin
tmp:=tmp*i;
x:=x div i;
y:=y div i;
end;
tmp:=tmp*x*y;
End;
NOK_:=tmp;
End;

and got WA #8. Compilation Error already no, but it is necessary to search error in your algorithm. Good luck.
Re: Pleasy help me! I have CE!
Posted by волчонок 10 Jul 2005 15:01
 Thank you, Very much!
  Now it works, I changed small mistake in LCM function.