Problem link: REMOVEMUL Problem - CodeChef
This code is correct(PYTHON 3):

``````for t in range(int(input())):
n,m = map(int,input().split())
q = list(map(int,input().split()))
sumtilln=n*(n+1)//2
print(int(sumtilln-sum(q)))
``````

This code is wrong(removed “/” on line 4):

``````for t in range(int(input())):
n,m = map(int,input().split())
q = list(map(int,input().split()))
sumtilln=n*(n+1)/2
print(int(sumtilln-sum(q)))
``````

This is the testcase it is failing on:

WHY ARE USE USING “//” instead of “/”?

“//” is used for floor division while"/" is used for normal division, why aren’t we dividing normally when it will always be perfectly divisible.

put it like this (n * (n + 1)) / 2

which forces the compiler to perform the multiplication first and then division, instead of first calculating (n + 1) / 2 which comes out to be float and then multiplying n.

And then you would be dealing with double which have precision problems and then multiplying it with another number and then converting it to int would result in decrease of 1 from correct answer in worst case.

Eg : 3 would be stored as 2.9999999…
and multiplying it with say 2 would give you 5.999999999…
and int(5.9999999…) will give you 5 not 6.

I tried it the way you are saying and I also tried multiplying in one step then dividing in the next. But it is giving the same error.