What is the difference between these two code snippets?
I'm solving [this][1] problem on CodeChef (which basically uses [SPOJ][2]), and my code is timing out. The problem basically states:

> Input
> 
> The input begins with two positive integers n k (n, k<=107). The next
> n lines of input contain one positive integer ti, not greater than
> 109, each. Output
> 
> Write a single integer to output, denoting how many integers ti are
> divisible by k. Example
> 
> Input: 
> 7 3 
> 
> 1 
> 
> 51 
> 
> 966369 
> 
> 7 
> 
> 9 
> 
> 999996 
> 
> 11
> 
> 
> Output: 4

When I saw the code of [another person's][3] submission, it is practically doing the same thing as mine, but it gets submitted successfully. Can you tell me why is my code taking more time than the other person's code, even when it's basically doing the same thing with more or less the same functions?

This is my code:

    n,k=gets.chomp.split
    k=k.to_i
    c=0
    n.to_i.times do
    if gets.chomp.to_i%k==0
     c+=1
     end
    end
    puts c


This is the other person's code

    inputline = gets.split(" ")
    t = inputline[0].to_i
    k = inputline[1].to_i
    counter = 0
    (1..t).each {
    numbers = (gets.to_i)
    if numbers%k == 0
    counter +=1
    end
    }
    puts counter

  [1]: http://www.codechef.com/problems/INTEST
  [2]: http://www.spoj.pl/problems/INTEST/
  [3]: http://www.codechef.com/viewsolution/1144096



What is the difference between these two code snippets?
===

I'm solving [this][1] problem on CodeChef (which basically uses [SPOJ][2]), and my code is timing out. The problem basically states:

> Input
> 
> The input begins with two positive integers n k (n, k<=107). The next
> n lines of input contain one positive integer ti, not greater than
> 109, each. Output
> 
> Write a single integer to output, denoting how many integers ti are
> divisible by k. Example
> 
> Input: 
> 7 3 
> 
> 1 
> 
> 51 
> 
> 966369 
> 
> 7 
> 
> 9 
> 
> 999996 
> 
> 11
> 
> 
> Output: 4

When I saw the code of [another person's][3] submission, it is practically doing the same thing as mine, but it gets submitted successfully. Can you tell me why is my code taking more time than the other person's code, even when it's basically doing the same thing with more or less the same functions?

This is my code:

    n,k=gets.chomp.split
    k=k.to_i
    c=0
    n.to_i.times do
    if gets.chomp.to_i%k==0
     c+=1
     end
    end
    puts c


This is the other person's code

    inputline = gets.split(" ")
    t = inputline[0].to_i
    k = inputline[1].to_i
    counter = 0
    (1..t).each {
    numbers = (gets.to_i)
    if numbers%k == 0
    counter +=1
    end
    }
    puts counter

  [1]: http://www.codechef.com/problems/INTEST
  [2]: http://www.spoj.pl/problems/INTEST/
  [3]: http://www.codechef.com/viewsolution/1144096


