VCT kiểm tra xem n có phải là một siêu số nguyên tố hay không

VCT kiểm tra xem n có phải là một siêu số nguyên tố hay không

0 bình luận về “VCT kiểm tra xem n có phải là một siêu số nguyên tố hay không”

  1. program so_nguyen_to;

    Uses crt;

    Var

              n:longint;

    function NT(x:longint):boolean;

    begin

             NT:=true;

             If x<2 then NT:=false else

             Begin

                      i:=2;

                       while n mod i<>0 do i:=i+1;

                       If i=n then NT:=true else NT:=false;

            End;

    End;

    Function SNT(a:longint):boolean;

    Var

              d,so:longint;

    Begin

              SNT:=true;

              if NT(a) then

              Begin

                       D:=1; so:=0;

                       while a<>0 do

                       Begin

                               inc(so); a:=a div 10; if NT(a) then inc(d);

                       End;

                       If d=so then SNT:=true else SNT:=false;

              End else SNT:=false;

    end;

    Begin

              clrscr;

              write(‘Nhap so muon kiem tra: ‘); readln(n);

              If SNT(n) then write(n,’ la so sieu nguyen to’) else write(n,’ khong la so sieu nguyen to’);

              Readln;

    End.

    Bình luận
  2. uses crt;
    var n, i, k, n1, n2: longint;
    function snt(n:longint):longint;
    begin
     for i:=1 to n-1 do
      begin
      if (n mod i = 0) then
       n:=1;
      if n mod i <> 0 then
       n:=2;
      if n=2 then n:=1;
      end;
    end;
    begin
     clrscr;
      write (‘nhap n: ‘);  readln (n);
      n1:=n;
      k:=1;
      while n>0 do
       begin
        n:=n1 mod 10;
        n1:=n1 div 10;
        snt(n);
        if (n=2) and (k=1) then k:=1;
        if (n=1) then k:=2;
       end;
        if k=1 then
         writeln (‘day la 1 sieu so nguyen to’)
        else
         writeln (‘ko phai’);
     readln;
    end.

    Bình luận

Viết một bình luận