This is my code in python for the Enormous Input Test problem :
while n>0 :
if x%k==0 :
How can i optimize this in a better way or what am doing wrong? i’m facing this problem in several of my python codes.Is there any way i can overcome this TLE problem?
import sys module and use sys.stdin.readline().strip() for raw_input() and use sys.stdout.write() for print.
@akarsh_hedge try importing the sys module for faster input output , it has always helped me , hope it helps you too .
You would clearly see the time difference on using sys .
I agree with both @its_pheonix and @vaibhav9518s , importing sys will surely help you .
thank u . will try that right away!
I am having same problem. I have tried both input() and sys.stdin.readline(). still TLE. This is also keeping me from earning full points on some competition problems as I believe my algorithms are often good save for i/o issues. This is frustrating as it seems as if Python submissions are being accepted they should be accommodated… otherwise wby accept them…
Here is my code for enormous input test:
n, k = [int(i) for i in sys.stdin.readline().strip().split()]
c = 0
for i in range(n):
if int(sys.stdin.readline().strip()) % k == 0:
c += 1