You are not logged in. Please login at www.codechef.com to post your questions!

×

input output in python

I am having issues with time limits and large inputs using python. I have tried both input() and sys.stdin.readline(). Fail 'enormous input test' in practice and also believe this issue is keeping me from earning full points on several problems in competitions. 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)

asked 04 Jan '15, 12:56

tao_of_coding's gravatar image

3★tao_of_coding
12
accept rate: 0%

edited 04 Jan '15, 13:00


Do not use strip and also use Python 2.7.

Here is your accepted solution.

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()) % k == 0:
        c += 1 
print(c)
link

answered 04 Jan '15, 13:17

the65bit's gravatar image

4★the65bit
1.1k101328
accept rate: 13%

edited 04 Jan '15, 13:21

Thank you!

(04 Jan '15, 19:10) tao_of_coding3★

Welcome!!! If it helped, Please upvote and accept it as correct answer ;)

(04 Jan '15, 19:24) the65bit4★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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:

×27
×24
×3

question asked: 04 Jan '15, 12:56

question was seen: 2,068 times

last updated: 04 Jan '15, 19:24