Вопрос школьника по предмету Информатика
Составить алгоритм получения всех совершенных чисел меньше N
Ответ учителя по предмету Информатика
Совершенным называется число, равное сумме всех своих делителей (включая 1, но исключая само число). Наименьшее из совершенных
чисел 6 равно сумме трех своих делителей 1, 2 и 3.
1.
var n,s,i,j:integer;
begin
write(‘n = ‘);
readln(n);
for i:=2 to n do
begin
s:=1;
for j:=2 to i div 2 do
if i mod j = 0 then s:=s+j;
if s=i then write(i,’ ‘);
end;
end.
Пример:
n = 1000
6 28 496
2.
алг Числа
нач
цел n,s,i,j
вывод «n =», нс
ввод n
нц для i от 2 до n
s:=1
нц для j от 2 до div(i,2)
если mod(i,j) = 0 то
s:=s+j
все
кц
если s = i то
вывод i, нс
все
кц
кон
Похожие вопросы от пользователей
Where is Ann? She ( to play ) tennis at the stadium.
Please, don’t make so much noise. Father ( to work ) in the study.
Don’t disturb me. I ( to watch ) the interesting program.
I ( not to laugh ) at you.
What journal you ( to read ) when I came to the library?
The whole family ( to have ) dinner when the telephone rang.
We ( to ski ) the whole day yesterday.
When I came to the party all guests ( to dance ).
She ( to learn ) English the whole day tomorrow.
The children ( to play ) when we returned home.
Look! It is getting dark. It ( to rain ) in a minute.
Where he ( to go ) when the rain started?
She ( to listen ) to a very interesting lecture at 5 o’clock tomorrow.
While my mother was cooking dinner I ( to lay ) the table.
They won’t go on excursion with us. They ( to have ) a lecture at 2 o’clock.
He is not learning new words, he ( to recite ) a poem now.
Mother ( to make ) a cake in the kitchen at the moment.
My brother ( to take ) a bath now. Wait for him.
The students of our group ( to write ) a dictation now.
Sophie is busy. She ( to knit ) a sweater for her grandson.