K
Khách

Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.

19 giờ trước (16:55)

#include <iostream>
using namespace std;

int tongUocThucSu(int x) {
if (x == 1) return 0;
int tong = 1;
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) {
tong += i;
if (i != x / i) tong += x / i;
}
}
return tong;
}

int main() {
int n;
cin >> n;

for (int a = 2; a < n; a++) { int b = tongUocThucSu(a); if (b > a && b < n) { if (tongUocThucSu(b) == a) { cout << a << " " << b << endl; } } } return 0;

}

Giải thích:
tongUocThucSu(x) dùng để tính tổng các ước thực sự của x, tức là các ước nhỏ hơn x
Với mỗi số a nhỏ hơn n, tính b = tổng ước thực sự của a
Nếu tổng ước thực sự của b lại bằng a thì a và b là hai số bạn bè
Điều kiện b > a để tránh in lặp lại 2 lần cùng một cặp

Ví dụ:
Input
300

Output
220 284

Lưu ý, ví dụ đúng là 220 và 284 là cặp số bạn bè, không phải 283 và 220 vì tổng các ước thực sự của 220 bằng 284.

16 tháng 3 2021

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.

16 tháng 3 2021

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.

13 tháng 3 2022

uses crt;

var n,i,t,j:integer;

begin

clrscr;

readln(n);

for i:=1 to n do 

  begin

t:=0;

for j:=1 to i div 2 do 

  if i mod j=0 then t:=t+j;

if t=i then write(i:4);

end;

readln;

end.

26 tháng 4 2021

a)

uses crt;

var n,i,t,j:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

t:=0;

for j:=1 to i-1 do 

 if i mod j=0 then t:=t+j;

if t=i then write(i:4);

end;

readln;

end.

26 tháng 4 2021

b)

uses crt;

var gt:real;

i,n:integer;

begin

clrscr;

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

gt:=1;

for i:=1 to n do 

 gt:=gt*i;

writeln(gt:0:0);

readln;

end.

16 tháng 3 2021

uses crt;

var n,i,t:integer;

begin

clrscr;

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

t:=0;

for i:=1 to n-1 do 

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

if t=n then writeln(n,' la so hoan chinh')

else writeln(n,' khong la so hoan chinh');

readln;

end.

6 tháng 11 2021

program hoan_chinh;

uses crt;

var n,i,s:integer;

begin

clrscr;

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

for i:=1 to n-1 do

 begin

 if n mod i = 0 then s:=s+i;

 end;

if s=n then writeln('1') {n là số chính phương thì viết 1}

else writeln('0');{n không là số chính phương thì viết 0}

end.

22 tháng 4 2021

uses crt;

var a:array[1..100]of real;

i,n:integer;

min,t:real;

begin

clrscr;

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

for i:=1 to n do 

  begin

write('A[',i,']='); readln(a[i]);

end;

min:=a[1];

for i:=1 to n do 

  if min>a[i] then min:=a[i];

writeln('Gia tri nho nhat la: ',min:4:2);

t:=0;

for i:=1 to n do 

 if i mod 2=0 then t:=t+a[i];

writeln('Tong cac phan tu co chi so chan la: ',t:4:2);

readln;

end. 

5 tháng 5 2021

Bài 1:

uses crt;

var n,i,s:integer;

begin

clrscr;

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

s:=0;

for i:=1 to n do 

 if i mod 6=0 then s:=s+i;

writeln(s);

readln;

end.

5 tháng 5 2021

Bài 2: 

uses crt;

var a,b,c,ucln,i:integer;

begin

clrscr;

write('a='); readln(a);

write('b='); readln(b);

write('c='); readln(c);

while a<>b do 

  begin

if a>b then a:=a-b

else b:=b-a;

end;

ucln:=a;

while ucln<>c do 

 begin

if ucln>c then ucln:=ucln-c

else c:=c-ucln;

end;

writeln(ucln);

readln;

end.

18 tháng 4 2021

program tim_uoc;

uses crt;

var i,n,tong:integer;

begin

clrscr;

write('nhap so n:');readln(n);

i:=1;tong:=0;

writeln('cac uoc cua ',n,' la:');

while i<=n do

if n mod i=0 then

begin

write(i:3);

inc(i);

end;

writeln;

i:=1;writeln('cac uoc chan:');

while i<=n do

begin

if n mod i=0 then 

begin

if i mod 2=0 then write(i:3);

tong:=tong+i;

end;

end;

writeln;

write('tong cac uoc chan:',tong);

readln;

end.

19 tháng 4 2021

uses crt;

var n,i,t:integer;

begin

clrscr;

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

i:=1;

writeln('Cac uoc cua ',n,' la: ');

while i<=n do

  begin

if n mod i=0 then write(i:4):

i:=i+1;

end;

writeln;

writeln('Cac uoc chan cua ',n,' la: ');

t:=0;

i:=1;

while i<=n do 

  begin

if (n mod i=0) then

begin

t:=t+i;

write(i:4);

end;

inc(i);

end;

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

readln;

end.

22 tháng 7 2023

program so_hoan_hao;

var

       n, tong_uoc, i: integer;

begin

       writeln('Nhap vao mot so nguyen duong n:');

       readln(n);

       tong_uoc := 0;

       for i := 1 to n-1 do

       begin

              if n mod i = 0 then

                     tong_uoc := tong_uoc + i;

       end;

       if tong_uoc = n then

              writeln('YES')

       else

              writeln('NO');

end.