A
A
asyasb2021-06-13 07:49:41
Python
asyasb, 2021-06-13 07:49:41

Why are odd divisors displayed along with even divisors?

The program should output 4 even divisors, but it also prints odd divisors (+ does not print the maximum divisor)

for x in range(190201,190280):
    sq=int(x**0.5)
    d=set()
    for i in range(1,sq+1):
        if x%i==0 and i%2==0:
            d.add(i)
            d.add(x//i)
    if len(d)==4:
        d=sorted(d)
        print(d)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
asyasb, 2021-06-13
@asyasb

if someone needs it, then here is another solution

for n in range(190201,190280+1):
  a = []
  for d in range(1,n+1):
    if n % d == 0 and d%2==0:
      a.append(d)
  if len(a) == 4:
      a.reverse()
      print(*a)

M
MDan_Twenty_One, 2021-06-13
@MDan_Twenty_One

Replace "if x%i==0 and i%2==0:" with "if x % i == 0 and i % 2== 0 and (x // i) % 2 == 0:"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question