×

# TLE . How can i optimize this better?

 2 This is my code in python for the Enormous Input Test problem : n,k=map(int, raw_input().split()) count=0 while n>0 : x=int(raw_input()) if x%k==0 : count=count+1 n-=1 print count  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? asked 22 Jul '14, 22:43 31●1●1●3 accept rate: 0%

 13 @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 . Happy Coding :) answered 23 Jul '14, 01:42 2.3k●6●20●21 accept rate: 11%
 2 import sys module and use sys.stdin.readline().strip() for raw_input() and use sys.stdout.write() for print. :) answered 23 Jul '14, 00:25 46●2 accept rate: 0% thank u . will try that right away! :) (24 Jul '14, 18:48)
 2 I agree with both @its_pheonix and @vaibhav9518s , importing sys will surely help you . answered 23 Jul '14, 01:45 3★proxy_s 31●1●3 accept rate: 0%
 0 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: import sys 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 print(c) answered 04 Jan '15, 12:52 1●2 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×727
×528

question asked: 22 Jul '14, 22:43

question was seen: 4,520 times

last updated: 04 Jan '15, 12:52