#include
using namespace std;
int main()
{
register int n,k,t,i,j;
j=0;
cin>>n;
cin>>k;
if(k<=10000000)
{
for(i=0;i<n;i++)
{
cin>>t;
if(t<=1000000000)
{
if (t%k==0)
{
j++;
}
cout<<j;
}
}
}
}
what’s wrong with this program …
steniom
2
cin, cout are slow. Use scanf, printf instead.
So here is your working code. This will work fine.
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int n,k,t,i,j;
j=0;
scanf("%d %d",&n,&k);
if(k<=10000000)
{
for(i=0;i<n;i++)
{
scanf("%d",&t);
if(t<=1000000000)
{
if (t%k==0)
{
j++;
}
}
}
printf("%d",j);
}
return 0;
}
Also you don’t need to assert that k, t are less than 10^7. They will always be under the constraints limit.
This question particularly tests for faster input output methods. cin/cout are considerably slower than scanf/printf.
You can also use getchar_unclocked() for reading integers. This is fastest method for reading integers.