I haven't been in these forums for a while... I've been learning much about Linux and about Perl and PHP :-)

I do know a lot of C, but not much C++, and I found a cool website that has an online judge and I've been working on some problems there.

Enormous Input Test

Code:

The purpose of this problem is to verify whether the method you are using to read input
data is sufficiently fast to handle problems branded with the enormous Input/Output
warning. You are expected to be able to process at least 2.5MB of input data per
second at runtime.
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

My program failed twice because of exceeded time limit. Here is my code:

Code:

#include <iostream>
using namespace std;
int main() {
long n, k, count = 0;
cin >> n >> k;
long *ti = new long[n];
for(int i = 0; i < n; i++) {
cin >> ti[i];
}
for(int i = 0; i < n; i++) {
if(ti[i] % k == 0)
count++;
}
cout << count;
}

What would be a better way to read all the input faster? I also tried reading from cin and testing for division on the same loop, but that was not fast enough either.

Thanks!