Những câu hỏi liên quan
Nguyễn Thuận
Xem chi tiết
Bùi Anh Tuấn
17 tháng 3 2021 lúc 20:05

Bình luận (0)
Bùi Anh Tuấn
17 tháng 3 2021 lúc 20:05

Bình luận (0)
Nguyễn Lê Phước Thịnh
17 tháng 3 2021 lúc 21:50

Câu 3: 

uses crt;

var n,i,kt:integer;

begin

clrscr;

write('Nhap n='); readln(n);

if n>1 then 

begin

kt:=0;

for i:=2 to trunc(sqrt(n)) do 

  if n mod i=0 then kt:=1;

if kt=0 then writeln(n,' la so nguyen to')

else writeln(n,' la hop so');

end

else writeln(n,' khong la so nguyen to cung khong la hop so');

readln;

end.

Bình luận (1)
Asuna
Xem chi tiết
Phía sau một cô gái
12 tháng 8 2023 lúc 20:16

def kiem_tra_nguyen_to(n):

    if n < 2:

        return False

    for i in range(2, int(n ** 0.5) + 1):

        if n % i == 0:

            return False

    return True

def kiem_tra_nguyen_to_cung_nhau(m, n):

    if kiem_tra_nguyen_to(m) and kiem_tra_nguyen_to(n):

        return True

    return False

M = int(input("Nhập số M: "))

N = int(input("Nhập số N: "))

if kiem_tra_nguyen_to_cung_nhau(M, N):

    print("Hai số", M, "và", N, "là hai số nguyên tố cùng nhau.")

else:

    print("Hai số", M, "và", N, "không phải là hai số nguyên tố cùng nhau.")

Bình luận (0)
Bùi Ngọc Khánh Huyền
Xem chi tiết
Nguyễn Lê Phước Thịnh
6 tháng 8 2023 lúc 17:47

Mình sẽ tạm hiểu đề này là viết chương trình in ra các số nguyên tố lớn hơn hoặc bằng n nha

#include <bits/stdc++.h>

using namespace std;

int n,m,i;

//chuongtrinhcon

bool ktnt(int n)

if (n<2) return false; 

for (int i=2; i*i<=n; i++) 

if (n%i==0) return false; 

return true;

}

int main()

{

cin>>n;

cout<<"Cac so nguyen to nho hon bang n thoa man yeu cau la"<<endl;

for (int i=2; i<=n; i++) 

if (ktnt(i)) cout<<i<<" ";

}

Bình luận (0)
nguyễn an phát
Xem chi tiết
Nguyễn Lê Phước Thịnh
26 tháng 3 2021 lúc 22:50

uses crt;

var i,n,m,k,d:integer;

{---------------chuong-trinh-con-tim-ucln--------------------}

function ucln(x,y:integer):integer;

var t:integer;

begin

while y<>0 do

begin

t:=x mod y;

x:=y;

y:=t;

end;

ucln:=x;

end;

{------------chuong-trinh-con-kiem-tra-so-nguyen-to-------------------}

function nt(b:longint):boolean;

var j:longint;

begin

nt:=true;

if (b=2) or (b=3) then exit;

nt:=false;

if (b=1) or (b mod 2=0) or (b mod 3=0) then exit;

j:=5;

while j<=trunc(sqrt(b)) do

begin

if (b mod j=0) or (b mod (j+2)=0) then exit;

j:=j+6;

end;

nt:=true;

end;

{---------------chuong-trinh-chinh---------------------}

begin

clrscr;

write('Nhap N: '); readln(N);

write('Nhap M: '); readln(M);

d:=0;

k:=ucln(N,M);

for i:=1 to k do

if nt(i) then d:=d+1;

if d>0 then writeln('2 so nay tuong duong voi nhau')

else writeln('2 so nay khong tuong duong voi nhau');

readln;

end.

Bình luận (1)
nguyễn an phát
3 tháng 6 2021 lúc 9:22

uses crt;

var i,n,m:integer;

a,b:array[1..100]of integer;

function nt(n:integer):boolean;

begin

  if n<2 then nt:=false;

  for i:=2 to n div 2 do

  if n mod i=0 then nt:=false;

end;

function nttd(n,m:integer):boolean;

var i,j,k,d,dem,s:integer;

a,b:array[1..100]of integer;

begin

  nttd:=false;

  d:=0;

  for j:=1 to n do

  if (nt(j))and(n mod j=0) then

  begin

    inc(d);

    a[d]:=j;

  end;

  dem:=0;

  for k:=1 to n do

  if (nt(k))and(m mod k=0) then

  begin

    inc(dem);

    b[dem]:=k;

  end;

  s:=0;

  if d=dem then for i:=1 to d do if a[i]=b[i] then

  inc(s);

  if s=d then nttd:=true else nttd:=false;

end;

BEGIN

  clrscr;

  write('nhap n,m:');readln(n,m);

  if nttd(n,m) then writeln(n,' va ',m,' la nguyen to tuong duong')

  else writeln(n,' va ',m,' khong phai la nguyen to tuong duong');

  readln;

END.

Bình luận (0)
nguyễn an phát
3 tháng 6 2021 lúc 9:24

uses crt;

Var M,N,d,i,luun,luum:integer;

Function USCLN(m,n: integer): integer;

Var r: integer;

Begin

luun:=n;luum:=m;

While n<>0 do

begin

r:=m mod n; m:=n; n:=r;

end;

USCLN:=m;

End;

function nttd:integer;

begin

  d:=USCLN(M,N); i:=2;

  While d<>1 do

  begin

    If d mod i =0 then

    begin

      While d mod i=0 do d:=d div i;

      While M mod i=0 do M:=M div i;

      While N mod i=0 do N:=N div i;

    end;

    Inc(i);

  end;

  If M*N=1 then Write(luum,'  va ', luun,' la so nguyen to tuong duong.')

  Else Write(luum ,' va  ',luun ,' khong phai la so nguyen to tuong duong.');

end;

BEGIN

  clrscr;

  Write('Nhap M,N:'); Readln(M,N);

  nttd;

  Readln;

END.

Bình luận (0)
Kamato Heiji
Xem chi tiết
Nguyễn Lê Phước Thịnh
16 tháng 3 2021 lúc 21:34

1:

uses crt;

var i,j,t,kt:integer;

begin

clrscr;

t:=0;

for i:=1 to 100 do 

  if i>1 then 

begin

kt:=0;

for j:=2 to i-1 do 

  if i mod j=0 then kt:=1;

if kt=0 then t:=t+i;

end;

writeln(t);

readln;

end.

Bình luận (4)
Nguyễn Lê Phước Thịnh
16 tháng 3 2021 lúc 21:35

Câu 2: 

*Viết chương trình:

uses crt;

var n,p,t:integer;

begin

clrscr;

write('Nhap n='); readln(n);

t:=0;

for p:=2 to n-1 do 

  if n mod p=0 then t:=t+p;

writeln('Tong cac uoc that su cua ',n,' la: ',t);

readln;

end.

Bình luận (0)
Yoriichi_Tsugikuni ( ɻɛɑ...
11 tháng 6 2021 lúc 14:57

Dễ mà bạn tự làm đi

Bình luận (0)
 Khách vãng lai đã xóa
T Đạt
Xem chi tiết
HT.Phong (9A5)
29 tháng 3 2023 lúc 16:00

Uses crt;

var n,i,z: integer;

begin clrscr;

readln(n);

for i:=1 to n do if(n mod i=0) then z:=z+1;

if(z=2) then writeln(z,' la so nguyen to')

else writeln(z,' khong phai la so nguyen to');

readln;

end.

Bình luận (0)
Nguyễn Hoàng Duy
29 tháng 3 2023 lúc 23:45

program PrimeNumber;

uses crt;

var
  N, i: integer;
  isPrime: boolean;

begin
  clrscr;
  write('Enter N: ');
  readln(N);

  if N <= 1 then
  begin
    writeln('N is not a prime number');
  end
  else
  begin
    isPrime := true;
    for i := 2 to trunc(sqrt(N)) do
    begin
      if N mod i = 0 then
      begin
        isPrime := false;
        break;
      end;
    end;

    if isPrime then
    begin
      writeln('N is a prime number');
    end
    else
    begin
      writeln('N is not a prime number');
    end;
  end;

  readln;
end.

Bình luận (0)
nam bảo
Xem chi tiết
Nguyễn Lê Phước Thịnh
24 tháng 2 2022 lúc 13:44

uses crt;

var n,m,i,dem,t,t1,d1:integer;

//chuongtrinhcon

function ktnt(var n:integer):boolean;

var i:integer;

kt:boolean;

begin

kt:=true;

for i:=2 to trunc(sqrt(n)) do 

  if n mod i=0 then kt:=false;

if (kt=true) then ktnt:=true

else ktnt:=false;

end;

//chuongtrinhchinh

begin

clrscr;

readln(n,m);

if (ktnt(n)=true) then writeln(n,' la so nguyen to')

else writeln(n,' ko la so nguyen to');

dem:=0;

t:=0;

for i:=2 to n do 

  if (ktnt(i)=true) then

begin

write(i:4);

t:=t+i;

dem:=dem+1;

end;

writeln;

writeln(t,' ',dem);

t1:=0;

d1:=0;

for i:=n to m do 

  if ktnt(i)=true then

begin

write(i:4);

t1:=t1+i;

inc(d1);

end;

writeln;

writeln(t1,' ',d1);

readln;

end.

Bình luận (0)
trần hoàng
Xem chi tiết
Nguyễn Lê Phước Thịnh
4 tháng 4 2022 lúc 21:53

#include <bits/stdc++.h>

using namespace std;

long long i,n,kt,j;

int main()

{

cin>>n;

for (i=2; i<=n; i++)

{

kt=0;

for (j=2; j*j<=i; j++)

if (i%j==0) kt=1;

if (kt==0) cout<<i<<" ";

}

return 0;

}

Bình luận (0)
Thu Anh
Xem chi tiết
Phía sau một cô gái
14 tháng 3 2023 lúc 15:44

program TongN;

var

     n, i, tong: integer;

begin

     tong := 0;

     writeln('Nhap so nguyen duong N: ');

     readln(n);

     i := 0;

     while i < n do

     begin

          i := i + 1;

          tong := tong + i;

     end;

     writeln('Tong cac so tu 1 den ', n, ' la ', tong);

     readln;

end.

Bình luận (0)