INTEST : Time Limit Exceeded in C++



I am trying to test my I/O methods via problem: INTEST On submitting it says time-limit exceeded. I previously submitted the similar problem in C, which gets accepted and takes 1.3 sec but for C++, its going beyond 8 sec. Is there any serious bug in my code or my I/O method is really so bad. Please help guys. As I am trying to switch from C to C++, its really demoralizing. Here is my source code:

#include <iostream>
using namespace std;

int main(){
  int test, div;
  cin >> test >> div;
  int count = 0;
  int num;
    cin >> num;
    count += (num%div ? 0 : 1);  
  cout << count << endl;
  return 0;


cout/cin simply is too slow, check the above link. You can either use scanf/printf for much faster I/O or as @kuruma explains - turn off auto sync with stdio and then using cout/cin will give you the time advantage.



hey i think as cin is tied with cout it will be slow

you can view my accepted code

here is link for more help


thanx guys…:smiley: