I
I
ilgiz12021-06-15 16:14:55
Python
ilgiz1, 2021-06-15 16:14:55

Why is the program not producing results?

Write a program that searches among the integers
belonging to the numerical interval [312614; 312651], numbers that
have exactly six different natural divisors

here is my code, but it does not give a result

for i in range(312614, 312652):
    dels = []
    for y in range(1, (i//2)+1):
        if i%y==0:
            dels.append(y)
    if len(dels)==6:
        print(i, dels)
    else:
        print('no')

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dmshar, 2021-06-15
@dmshar

A very strange question. And what number, in your opinion, from the range [312614; 312651], has exactly six different natural divisors? Given that you have written a program in such a way that you also consider "1" a divisor.

R
Rsa97, 2021-06-15
@Rsa97

1 is a natural divisor of any natural number, the number itself is also a natural divisor of itself.
Your mistake is that you check up to the root of the number and skip divisors that are greater than this value. You can do that, but then you should consider that each divisor has a pair (divider and value/divider), except for the case when divider == value/divider.
312628: 1, 2, 4, 78157, 156314, 312628
312651: 1, 3, 9, 34739, 104217, 312651

M
Mikhail Krostelev, 2021-06-15
@twistfire92

Try adding one line to your code and see why the program didn't produce a result.

for i in range(312614, 312652):
  dels = []
  for y in range(1, (i//2)+1):
    if i%y==0:
      dels.append(y)
  print(i, len(dels),  dels)
if len(dels)==6:
  print(i, dels)
else:
  print('no')

Spoiler:
You don't take i itself as a divisor. So you need to compare not with 6, but with 5, because. Any number is 100% divisible by itself. then a couple of numbers will fall.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question