tính tổng các số hoàn hảo nhỏ hơn n bằng pascal. mình rất cần
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.
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.
Program HOC24;
var i,t,k,n: integer;
begin
write('Nhap N: '); readln(n);
t:=0; k=0;
while k=0 do
begin
n:=n+1;
for i:=1 to n do if n mod i=0 then t:=t+i;
if t=n then
begin
write(n);
k:=k+1
end else t:=0;
end;
readln
end.
Cho biến i chạy từ 1 đến n. Xét i. Nếu nó là số hoàn chỉnh thì in ra.
Program Tim_uoc_2;
uses crt;
Var S, n, i,j: longint;
Begin
clrscr;
Write('Nhap so n ='); readln(n);
For i:=1 to n do
Begin
S:=0;
For j:=1 to i do if i mod j = 0 then S:=S+j;
if S = 2*i then write(i:6,',');
end;
readln
end.
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 do
if i mod j=0 then t:=t+j;
if t=i then write(i:4);
end;
readln;
end.
uses crt;
var n,i,kt,j,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
writeln('Cac so nguyen to trong khoang tu 2 toi ',n,' la: ');
for i:=2 to n do
begin
kt:=0;
for j:=2 to i-1 do
if i mod j=0 then kt:=1;
if kt=0 then write(i:4);
end;
writeln;
writeln('Cac so chinh phuong trong khoang tu 0 toi ',n,' la: ');
for i:=0 to n do
if trunc(sqrt(i))=sqrt(i) then write(i:4);
writeln;
writeln('Cac so hoan hao trong khoang tu 1 toi ',n,' la: ');
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.
program bai_toan;
var
N, i, sum: integer;
begin
write('Nhap so N: ');
readln(N);
write('Cac uoc cua ', N, ' khong ke ', N, ' la: ');
for i := 1 to N - 1 do
if N mod i = 0 then
write(i, ' ');
writeln;
sum := 0;
for i := 1 to N - 1 do
begin
if N mod i = 0 then sum := sum + i;
end;
if sum = N then writeln(N, ' la so hoan hao')
else writeln(N, ' khong phai la so hoan hao');
writeln;
writeln('Tat ca so hoan hao trong pham vi 1 -> ', N, ' la:');
for i := 1 to N do
begin
sum := 0;
for j := 1 to i - 1 do
begin
if i mod j = 0 then sum := sum + j;
end;
if sum = i then writeln(i);
end;
readln;
end.
program TinhTongVaUoc;
var
a, b, sum, i: integer;
uoc: boolean;
begin
write('Nhap so a: ');
readln(a);
write('Nhap so b: ');
readln(b);
// Tinh tong a+b
sum := a + b;
writeln('Tong cua a va b la: ', sum);
// In ra cac uoc cua tong
write('Cac uoc cua tong a+b la: ');
for i := 1 to sum do
begin
if sum mod i = 0 then
write(i, ' ');
end;
writeln;
// Kiem tra xem tong a+b co phai la so hoan hao hay khong
uoc := false;
for i := 1 to sum - 1 do
begin
if sum mod i = 0 then
uoc := true;
end;
if uoc and (sum = 2 * sum div 2) then
writeln('Tong a+b la so hoan hao')
else
writeln('Tong a+b khong phai la so hoan hao');
end.
a
ta có 1 số hoàn hảo = tổng các ước = 2 lần nó
ta có các ước của 28=[1,2,,4,7,14,28]
mà tổng các tích của nó là 1+2+4+7+14+28=56=28x2
nên 28 là số hoàn hảo
b
gọi a1,a2,a3,......ak là ước của n
vì n hoàn hảo nên
[n:a1]+[n:a2]+..................+[n:ak]=2n
=[nx[1;a1]+nx[1:a2]+...............+nx[1:ak]=2n
=nx[1;a1+1:a2+1:a3+...............+1:ak]=2n
nên [1;a1+1;a2+1;a3+...............+1:ak]=2
mình chỉ giúp được bạn câu a,b thôi chứ không giúp được câu c xin lỗi nhé
uses crt;
var n,i,t,j,t1:integer;
begin
clrscr;
readln(n);
t:=0;
for i:=1 to n do
begin
t1:=0;
for j:=2 to n div 2 do
if i mod j=0 then t1:=t1+j;
if t1=i then t:=t+i;
end;
writeln(t);
readln;
end.