Answer the question
In order to leave comments, you need to log in
I rewrote the program from Pascal to JS and it doesn't work. What is the reason?
The program itself must find all integers from 1 to 300 that have five divisors.
Pascal Code
var
i, j, k: integer;
begin
for i := 2 to 300 do
begin
k := 0;
for j := 2 to i do
if (i mod j = 0)and (k < 6) then inc(k);
if k = 5 then write(' ', i);
end
end.
for(i=2; i<300; i++){
k=0;
for(j=2; j<i; j++){
if(i%j===0 && k<6){
k++;
}
}
if (k===5){
alert(i);
}
}
Answer the question
In order to leave comments, you need to log in
As far as I understand, in the range 1-300, only the number 46 has five divisors, and the rest of the numbers have more or less. (And actually six, for some reason you don’t count one)
Because of the condition, if(i%j===0 && k<6)
often the variable k reaches six. I changed the log output a little bit https://jsfiddle.net/Lywpupne/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question