Friday, 1 November 2013

Enormous Input Test - Solution


Problem Statement :
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

Solution
#include<stdio.h>
 
int main()
{
        long i,n,k,counter=0,number;
        scanf("%d%d",&n,&k);
        for(i=0;i<n;i++)
        {
               scanf("%d",&number);
               if(number%k==0)
                       counter++;
        }
        printf("%d",counter);
        return 0;
        
}

1 comment:

  1. // I did the same thing in C++ but I am not getting the correct solution.Please Help!
    //My Code is as follows
    #include

    using namespace std;

    int main()
    {
    int n,k;
    cin>>n>>k;
    int a[n];
    int count;
    for(int i=0;i>a[i];
    if (a[i]%k==0)
    {
    count++;
    }
    }
    cout<<count;
    }

    ReplyDelete