Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:06:23+00:00 2026-06-02T15:06:23+00:00

I started learning programming a few months ago and just recently found codechef .

  • 0

I started learning programming a few months ago and just recently found codechef.
The problem is that on problems that use large amounts of input my code alwaqys exceehe time limit. I can’t even seem to make the input test work.

Description from codechef:

Input

The input begins with two positive integers n k (n, k<=10^7). The next
n lines of input contain one positive integer ti, not greater than
10^9, each.

Output

Write a single integer to output, denoting how many integers ti are
divisible by k.

Here’s the code:

n, t = [int(x) for x in input().split()]
c = 0
for i in range(n):
    if not int(input()) % t:
        c += 1
print(c)

I’m not sure what I’m missing. How can I handle this faster?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:06:24+00:00Added an answer on June 2, 2026 at 3:06 pm

    This should really be a comment, but anyway.

    Note that there’s an accepted Python 2 solution here, with runtime 45.77s, so it’s clearly possible. I think you’re a victim of Python 3’s slow I/O (looks like they’re using 3.1.2). On a two million line input file (which happens not to have any numbers which are divisible): there’s not much difference when there are a lot), on a version of your code modified to be compatible with 2 and 3, I get:

    ~/coding$ time python2.6 enormread.py < sample.txt 
    0
    
    real    0m3.971s
    user    0m3.712s
    sys 0m0.256s
    ~/coding$ time python2.7 enormread.py < sample.txt 
    0
    
    real    0m2.637s
    user    0m2.428s
    sys 0m0.204s
    ~/coding$ time python3.2 enormread.py < sample.txt 
    0
    
    real    0m10.412s
    user    0m10.065s
    sys 0m0.344s
    ~/coding$ time ~/sys/Python-3.3.0a2/python enormread.py < sample.txt 
    0
    
    real    0m6.776s
    user    0m6.336s
    sys 0m0.436s
    ~/coding$ time pypy enormread.py < sample.txt 
    0
    
    real    0m2.211s
    user    0m1.948s
    sys 0m0.028s
    

    To throw @agf’s (sum(not int(line) % t for line in sys.stdin[.buffer])) into the mix:

    ~/coding$ time python2.7 enormfast.py < sample.txt 
    0
    
    real    0m1.454s
    user    0m1.436s
    sys 0m0.016s
    ~/coding$ time python3.2 enormfast.py < sample.txt 
    0
    
    real    0m2.243s
    user    0m2.228s
    sys 0m0.012s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started learning how to program a few months ago and this is
I started learning programming 4 months ago. So far I already know some javascript(and
I've just started learning Functional Programming (Scheme). But I still have problems thinking functionally.
I just started studying programming about 6 months ago and I have really been
I started learning JavaScript a while ago. It's a fairly easy programming language considering
So I'm really new to programming, I just started learning Python yesterday and I'm
I'm a real noob who just started learning 3d programming and i have a
I do Java programming and recently started learning Python via the official documentation. I
I'm a Java guy who is familiar with Swing programming and recently just started
I have recently started learning Ruby, as my first programming language. I feel comfortable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.