I don’t see the difference between the 3rd and 4th code in this clash:

but apparently there is a mistake in the 4th solution. Maybe I don’t realize something, but I find these codes equivalent. Can someone explain this?

I don’t see the difference between the 3rd and 4th code in this clash:

but apparently there is a mistake in the 4th solution. Maybe I don’t realize something, but I find these codes equivalent. Can someone explain this?

n = int(input()) + 1

t = 0

for i in range(1,n):

_ if i % 7 == 0: t += 1

_ elif ‘7’ in str(i): t += 1

_ elif sum(int(j) for j in str(i)) % 7 == 0: t += 1

print(t)

vs.

import sys

import math

s=0

for i in range(1,int(input())+1):

_ if i%7==0 or str(i).count(“7”)>0 or sum(int© for c in str(i))%7==0: s+=1

print(s)

```
from time import perf_counter
a = perf_counter()
for i in range(1,1000000):
t = 0
if i % 7 == 0: t += 1
elif '7' in str(i): t += 1
elif sum(int(j) for j in str(i)) % 7 == 0: t += 1
print(perf_counter() - a)
a = perf_counter()
for i in range(1,1000000):
s=0
if i%7==0 or str(i).count("7")>0 or sum(int(c) for c in str(i))%7==0: s+=1
print(perf_counter() - a)
```

You can notice that the second solution takes slightly more time.

That could be enough to create a timeout.

It’s the only explanation I can think of.

2 Likes

Thank you, this is the only explanation I can imagine.