This question relates to my code running into Time Limit Exceeded Error
on Codechef- although the time clocked is 0 seconds?
Here is the problem I am trying to solve: https://www.codechef.com/SEPT21C/problems/MNDIGSUM
And here is my code:
Q = int(input())
res = float("inf")
curr = float("inf")
answer = float("inf")
#converts any positive integer 'temp' with base 10 into its equivalent in base 'base'
def numberToBase(n, b,stopper):
counter = 0
if n == 0:
return [0]
digits = []
while n:
digits.append(int(n % b))
counter += int(n % b)
n //= b
if counter>stopper:
break
return sum(digits[::-1])
for i in range(Q):
answer = float("inf")
res = float("inf")
curr = float("inf")
count = float("inf")
(n,l,r) = list(map(int,input().split()))
for j in range(l,r+1):
count = min(count,curr)
curr = numberToBase(n,j,curr)
if curr<res:
answer = j
res = min(res,curr)
print(answer)
Am I missing something- because when I run my code in PyCharm, and run the basic three tests on the website, it produces the same output as expected!
I looked on a number of forums and there was a mention of the CodeChef compiler reading my inputs too slowly? But I've never had this problem when answering previous problems in the same manner, I mean in terms of setting up the input.