Advertisement
Guest User

Train2020.pas

a guest
Jan 20th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. var a,u,b: array[1..100] of byte;
  2. n,max,i: byte;
  3.  
  4. function gcd(a,b: byte): byte;
  5. begin
  6. if b=0 then gcd:=a
  7. else gcd:=gcd(b, a mod b)
  8. end;
  9.  
  10. function R(k, pred: byte): byte;
  11. var i: byte;
  12. begin
  13. if k>max
  14. then begin
  15. max:=k;
  16. for i:=2 to max do b[i]:=a[i];
  17. end;
  18. for i:=2 to n do
  19. if (u[i]=0) and ((pred=0) or (gcd(pred, i)>1))
  20. then begin
  21. u[i]:=1; a[k+1]:=i;
  22. R(k+1, i);
  23. u[i]:=0;
  24. end;
  25. end;
  26.  
  27. begin
  28. read(n); max:=1;
  29. R(1,0);
  30. write(1);
  31. for i:=2 to max do write('-', b[i]);
  32. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement