3
3
3DOSES2021-01-20 15:14:13
Python
3DOSES, 2021-01-20 15:14:13

Look at a simple problem, why not right?

On one site this problem is given

The set of integers belonging to the numerical segment [4668; 10414], which are divisible by 3 or 11 and are not divisible by 2, 13, 22, 33. Find the number of such numbers and the minimum of them. In your answer, write down two integers without spaces or other additional characters: first the number, then the minimum number.


Immediately I say her correct answer is
9654671


I wrote a solution in python, but I get a completely different answer and I don't understand why.
My decision
a = 0
b = 4668

for i in range(4668, 10414+1):
  if i % 3 == 0 or i % 11 == 0 and i % 13 != 0 and i % 22 != 0 and i % 33 != 0:
    a = a + 1
    b = i

print(a,b)


I get the answer
207710413


What's my mistake?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ihor, 2021-01-20
@3DOSES

1. We missed the condition i % 2 != 0
2. We were looking for the maximum and not the minimum
3. The priority of the and, or operators was not correctly performed

l = []
for i in range(4668, 10414+1):
    if (i % 3 == 0 or i % 11 == 0) and (i % 2 != 0 and i % 13 != 0 and i % 22 != 0 and i % 33 != 0):
        l.append(i)

print(len(l), min(l))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question