Why am i getting runtime error on codechef when it runs fine on my computer?

import math
n,k=input().split(' ')
n,k=int(n),int(k)
st=set()
for i in range(k):
c=int(input())
for j in st:
k=math.gcd(c,j)
if k==c:
st.discard(j)
elif c==j:
break
else:
st.add(c)
sum=0
ln=len(st)
for v in st:
sum+=1+(n-1)//v
print(n-sum+(ln*(ln+1))//2+1)
i had submitted the above code as a solution to a problem. It ran fine on my ide and with custom input. But running it otherwise or submitting returns a runtime error(eof while running). Why is this so?
this is the problem i was solving https://www.codechef.com/IARCSJUD/problems/LEAFEAT
  • Format your code as the forum software messed it up.

  • Give the link to problem which you are trying to solve.

  • Explain your source-code in plain english, what idea you are trying to implement, yeah we can go through your code but it will be time consuming, it would be better if you explain it.

After doing the above things, then you can expect help from the community.

Thanks for Reading
Peace :v:

2 Likes