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.

22 tháng 4

#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.

28 tháng 8 2021

uses crt;

var n,i,o,d:integer;

function ktnt(n:integer): integer;

var i,d:integer;

begin

d:=0;

for i:=1 to sqrt(n) do

if (n mod i=0) then d:=d+1;

if d=2 then ktnt=0

else ktnt=1;

end;

begin

readln(n);

writeln(' so nguyen to be hon hoac bang n la'); {a}

for i:=1 to n do

if ktnt(i)=0 then writeln(i);

writeln('so nguyen to nho nhat khong be hon n');

o:=n;

while o>0 do

begin

if ktnt(o)=0 then

begin

write(o);

break;

end;

o:=o+1;

end;

writeln('cặp số nguyên tố là hai số nguyên lẻ liên tiếp nhỏ hơn hoặc bằng n');

o:=0;

o:=1;

d:=0;

for i:=o+2 to n do

begin

if ktnt(i)=0 then

begin

d:=d+1;

write(i,' ');

if d<2 then continue;

end;

d:=0;

writeln;

end;

readln;

end.

28 tháng 8 2021

Mình nói thật nhé là ko có 2 số lẽ liên tiếp nhé

vd n+2 với n là 1

thì số lẻ tiếp theo của nó là (n+2)+2 tức n+4 đấy còn liên tiếp (n+2)+1 là ko bao giờ xãy ra

 

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.

29 tháng 4 2022

Var i,s:integer;

Begin

i:=0;

While s<=1000 do

Begin

i:=i+1;

s:=s+i;

End;

Write('n nho nhat la ',i);

Readln;

End.

11 tháng 5 2021

Bài 3:

uses crt;

var i:integer;

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

function ktnt(x:integer):boolean;

var kt:boolean;

i:integer;

begin

kt:=true;

for i:=2 to x-1 do

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

if kt=true then ktnt:=true

else ktnt:=false;

end;

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

begin

clrscr;

for i:=2 to 9999 do 

  if (ktnt(i)=true) and (ktnt(i+2)=true) then 

begin

writeln(i,',',i+2);

delay(500);

end;

readln;

end.

11 tháng 5 2021

Bài 4: 

uses crt;

var a,b,c,kt:integer;

begin

clrscr;

write('Nhap ngay:'); readln(a);

write('Nhap thang:'); readln(b);

write('Nhap nam:'); readln(c);

kt:=0;

if (b=1) and (0<a) and (a<=31) then kt:=1;

if (b=2) and (0<a) and (a<=28) then kt:=1;

if (b=2) and (0<a) and (a<=29) and (c mod 4=0) then kt:=1;

if (b=3) and (0<a) and (a<=31) then kt:=1;

if (b=4) and (0<a) and (a<=30) then kt:=1;

if (b=5) and (0<a) and (a<=31) then kt:=1;

if (b=6) and (0<a) and (a<=30) then kt:=1;

if (b=7) and (0<a) and (a<=31) then kt:=1;

if (b=8) and (0<a) and (a<=31) then kt:=1;

if (b=9) and (0<a) and (a<=30) then kt:=1;

if (b=10) and (0<a) and (a<=31) then kt:=1;

if (b=11) and (0<a) and (a<=30) then kt:=1;

if (b=12) and (0<a) and (a<=31) then kt:=1;

if kt=0 then writeln('Khong hop le')

else writeln('Hop le');

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.

21 tháng 2 2022

giúp mình với

 

21 tháng 2 2022

cảm ơn

 

17 tháng 3 2021

program tim_n;
uses crt;
var tong,n,i:word;
begin
  clrscr;
  n:=1;tong:=0;
  while tong<500 do
  begin
    for i:=1 to n do tong:=tong+i;
    if tong<500 then begin tong:=0;n:=n+1;end
    else n:=n-1;
  end;
  write('so n thoa man dieu kien la:',n);
  readln;
end. 

17 tháng 3 2021

uses crt;

var i,n,t:integer;

begin

clrscr;

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

t:=0;

for i:=1 to 500 do 

begin  

t:=t+i;

if t>500 then 

begin

writeln(i);

break;

end;

end;

readln;

end.

17 tháng 3 2021

uses crt;

var n:integer;

s:real;

begin

clrscr;

s:=1/1000;

n:=1 div s;

while s<=1/1000 do 

  begin

n:=n-1;

s:=1/n;

end;

writeln(n);

readln;

end.

KHÓ QUÁ BẠN ƠI MÌNH LỚP 12 MÀ CHỊU ĐÓ

29 tháng 3 2018

in ra số lớn nhất thì mình nghĩ có cách này :/ 
program abc; 
uses crt; 
var a,b,c,dmax : integer; 
begin 
clrscr; 
write ( ' nhap a =' ); 
readln (a); 
write ( ' nhap b = '); 
readln (b); 
write ( ' nhap c =' ); 
readln (c); 
write ( ' nhap d = ' ); 
readln (d); 
a:=max; 
if max<b then max:=b; 
if max<c then max :=c; 
if max<d then max :=d; 
write ( ' so lon nhat la',max); 
readln; 
end. 
( mình không chắc nha :I )