Help in Printing Sheets practice problem

My code for this problem( http://www.codechef.com/problems/IOPC13D ) is :-

#include<iostream>
using namespace std;
int main()
{
	int t,n;
	cin>>t;
	while(t--)
    {
		cin>>n;
		if(n%3==0 || n%2==0)	cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
return 0;
}

This code of mine is giving a TLE whereas , the peice of code given below got an AC

#include<iostream>
using namespace std; 
int main() 
{
  int t, n;
  scanf("%d",&t);  
  while(t--) 
  {
    scanf("%d",&n);
    if(n%2==0 || n%3==0) 
    printf("YES\n");
    else 
    printf("NO\n");
  }
  return 0;
}

I fail to understand why I got a TLE. Help please!

Please post the ideone links of both your codes.

The constraints mentioned for number of test case is:

1 ≤ T ≤ 5*(10^5), which is infact large.

scanf(stdio) supposed to be faster than cin(iostream), hence the TLE.

2 Likes

You are right…i changed my cin to scanf as well as had to change cout to printf.
But it could have been so miserable if things like these would’ve happened in a running contest.
Thanks a lot.

But it won’t be miserable if the the constraints are clearly mentioned.