cook your dish here
for i in range(t):
for i in range(2,k):
for j in range(0,i):
for p in range(len(l1)):
Look at constraints 2 ≤ k ≤ (10^12).So your code just fails!
can you please give me hint what should i do if some test case has large inputs , actually it had done twice that my code does not work for large inputs
try to develop a logic in the number making which can reduce for while loop
I found that 8624 repeats but I m not able to relate
Problem is not with large inputs.But actually complexity.Here ur code will perform roughly 10^12 operations.But the max is 10^8.So you just have to come up with more optimal solution.