Answer the question
In order to leave comments, you need to log in
How is this task from the Unified State Examination in Informatics solved?
The essence of the problem: you need to write a program that searches among integers belonging to the numerical interval [174457; 174505], numbers that have exactly two different natural divisors, not counting one and the number itself. For each found number, write these two divisors in two adjacent columns on the screen from a new line in ascending order of the product of these two divisors. Divisors in a string must also be in ascending order.
For example, in the range [5; 9] exactly two different natural divisors have numbers 6 and 8, so for this range the output on the screen should contain the following values:
2 3
2 4
The way I tried to solve this problem:
a = 174457
b = 174505
k = 0
d = []
for n in range(a, b+1):
if n%2 == 0:
k+=1
d.append(n)
if k > 2:
break
if k == 2:
print(d[0], d[1])
var
x, numDel, i, j: longint;
d: array[1..2] of longint;
begin
for i := 174457 to 174505 do begin
numDel := 0;
for j := 2 to i div 2 do begin
if i mod j = 0 then begin
numDel := numDel + 1;
if numDel > 2 then break;
d[numDel] := j;
end;
end;
if numDel = 2 then writeln(d[1], ' ', d[2]);
end;
end.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question