Can someone please tell me how to decrease the execution time of my code? Currently it is 5.48
Following is my code :
#include <iostream>
using namespace std;
int main() {
int n,k,cnt=0,t;
scanf("%d%d",&n,&k);
while(n)
{
scanf("%d",&t);
if(t%k==0)
cnt++;
n--;
}
printf("%d",cnt);
return 0;
}
Further, I have just started participating on codechef so can someone please guide me about what are the topics that one must know so that they can attempt the questions?
Thanks a lot.
NO optimization can be performed on the division part. The only place you can reduce run time is by reducing the time it takes to input and output a number. printf and scanf are normally slower compared to some other functions available for input. Here are links to discussions on fast input/output methods. link
As far topics is concerned, i would suggest you start solving easy questions and participating in contests. You will come to know about them over course of time. Programming is more about logic and experience then just reading and understanding theoretical concepts.
If you will use another header file #include and use the compiler C++ 4.8.1…
Then your execution time will be 4.81 …and what @kcahdog said ,is also true …