Những câu hỏi liên quan
hoàng đá thủ
Xem chi tiết
Nguyễn Lê Phước Thịnh
29 tháng 8 2023 lúc 21:00

uses crt;

var i,n,t,j,kt:integer;

begin

clrscr;

readln(n);

t:=0;

for i:=2 to n do

if n mod i=0 then

begin

kt:=0;

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

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

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

end;

write(t);

readln;

end.

Bình luận (1)
Lê Minh Thuận
30 tháng 8 2023 lúc 16:38

Dưới đây là một ví dụ về chương trình Pascal để tính tổng các ước số nguyên tố của một số tự nhiên n:

```pascal
program TinhTongUocSoNguyenTo;
var
n, i, j, sum: integer;
isPrime: boolean;
begin
write('Nhap vao so tu nhien n: ');
readln(n);

sum := 0;

for i := 1 to n do
begin
if n mod i = 0 then // Kiểm tra i có là ước số của n không
begin
isPrime := true;

for j := 2 to trunc(sqrt(i)) do // Kiểm tra i có phải là số nguyên tố không begin if i mod j = 0 then begin isPrime := false; break; end; end; if isPrime then // Nếu i là số nguyên tố, cộng vào tổng sum := sum + i; end;

end;

writeln('Tong cac uoc so nguyen to cua ', n, ' la: ', sum);
end.
```

Chương trình trên sẽ yêu cầu bạn nhập vào số tự nhiên n, sau đó tính tổng các ước số nguyên tố của n và hiển thị kết quả.

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
Lăm A Tám Official
Xem chi tiết
Do Ngoc Thao My
Xem chi tiết
TKT VN
Xem chi tiết
nguyễn an phát
1 tháng 9 2021 lúc 11:21

program bai_1;
uses crt;
var i,n,j,d,dem:word;
begin
  clrscr;
  repeat
    write('nhap n:');readln(n);
    if (n<=0)or(n>=10000)then writeln('so ban nhap khong hop le, ban hay nhap lai:');
  until (n>0)and(n<10000);
  writeln('cac uoc so la so tu nhien cua ',n,' la:');
  for i:=1 to n do
  if n mod i=0 then write(i,'    ');
  writeln;
  dem:=0;
  for i:=2 to n do
  begin
    d:=0;
    for j:=2 to i div 2 do
    if i mod j=0 then inc(d);
    if (d=0)and(n mod i=0)then inc(dem);
  end;
  if dem>0 then writeln('cac uoc so la so nguyen to cua ',n,' la:');
  begin
    d:=0;
    for j:=2 to i div 2 do
    if i mod j=0 then inc(d);
    if (d=0)and(n mod i=0)then write(i,'    ');
  end;
  if dem=0 then write(0);
  readln;
end.

 

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)
SKT_Rengar Thợ Săn Bóng...
Xem chi tiết
Trang Thuỳ
Xem chi tiết
Nguyễn Lê Phước Thịnh
5 tháng 4 2022 lúc 14:09

#include <bits/stdc++.h>

using namespace std;

long long n,i,t,j;

bool kt;

int main()

{

cin>>n;

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

{

kt=true;

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

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

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

}

cout<<endl;

t=0;

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

if (n%i==0) t+=i;

cout<<t;

return 0;

}

Bình luận (0)
Trang Tritiny Betha
Xem chi tiết
✓ ℍɠŞ_ŦƦùM $₦G ✓
27 tháng 12 2015 lúc 19:00

n=p.q

mà p;q là các số nguyên tố

=>Ư(n)={1;p;q;n)

=>n=1+p+q=pq

=>1+q=pq-p

=>1+q=p(q-1)

=>2+q-1=p(q-1)

=>p(q-1)-(q-1)=2

=>(p-1)(q-1)=2

2=1.2

=>p-1=1 hoặc p-1=2

p-1=1=>p=2;q-1=2=>p=3

=>n=3+2+1=6

p-1=2=>p=3;q-1=1=>q=2

=>n=3+2+1=6

Vậy n=6

Bình luận (0)