tuki2501

dayhanhphuc

Sep 4th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.75 KB | None | 0 0
  1. uses crt;
  2. var
  3.   a:array[1..100000000] of longint;
  4.   i,n,c:longint;
  5.  
  6. function priNum(x:longint):boolean;
  7. var
  8.   i:longint;
  9.   tmp:boolean;
  10. begin
  11.   tmp:=true;
  12.   if x=1 then tmp:=false
  13.   else
  14.     for i:=2 to x div 2 do
  15.       if x mod i = 0 then tmp:=false;
  16.   priNum:=tmp;
  17. end;
  18.  
  19. function divNum(x,c:longint):boolean;
  20. var
  21.   i:longint;
  22.   tmp:boolean;
  23. begin
  24.   tmp:=false;
  25.   for i:=c-1 downto 1 do
  26.     if a[i] mod x = 0 then
  27.       tmp:=true;
  28.   divNum:=tmp;
  29. end;
  30.  
  31. procedure solve();
  32. begin
  33.   write(n,' ');
  34.   a[1]:=n;
  35.   c:=2;
  36.   for i:=n-1 downto 1 do
  37.     if (priNum(i) or divNum(i,c)) then
  38.       begin
  39.         write(i,' ');
  40.         a[c]:=i;
  41.         inc(c);
  42.       end;
  43. end;
  44.  
  45. begin
  46.   clrscr();
  47.  
  48.   readln(n);
  49.   solve();
  50.  
  51.   readln();
  52. end.
Advertisement
Add Comment
Please, Sign In to add comment