You were missing an end of line after cout << sum;, which I have added.
Then, as already suggested, you can either replace cin/cout with scanf/printf, or, as an alternative, you can turn off the automatic synchronization that cin/cout do with stdio, in order to gain more time.
As such, the code below (which is basically your code with the endl added and with the detail above added), gets AC with 4.25 sec:
#include<iostream>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false); //this was added
int a,i=0,sum=0;
long k,temp;
cin>>a>>k;
while(i<a)
{
cin>>temp;
if(temp%k==0)
sum=sum+1;
i++;
}
cout<<sum << endl; //an end of line was added here as well
}
Note, in particular: “If the synchronization is turned off, the C++ standard streams are allowed to buffer their I/O independently, which may be considerably faster in some cases.”