Nafis is working on a mathematical project. But he is stuck on a step of it. In this step, numerous …
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
Why my code got TLE?
Here is my code for this problem:
def multi(myList) :
result = 1
for x in myList:
result *= x
return result
t = int(input())
for i in range(t):
k,n=map(int,input().split())
x = 1
s=[]
while True:
s.append(1+x*k)
if x*k>n:
break
x += 1
s.pop()
print('Case '+str(i+1)+': '+str(multi(s)%(10**9+7)))
In each of the test cases, you are running a loop to calculate the answer. This is not well optimized. It is natural that you’re getting CLE verdict. See the editorial.
By the way, “227” in the editorial is actually “227”. I think that’s formating or typing mistake.