Did't find from google

why using for loop will not give TLE insted using while.(to iterate testcase)
ex->> Solution: 42640665 | CodeChef (TLE with while)
(acc. but wa)
#include <bits/stdc++.h>
#include
#include
#define ll long long int
using namespace std;

int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t=0;
cin>>t;
for(int i=0; i<t; i++)
//while(t–)
{ // cout<<“Chef”<<endl;

ll x=0,y=0;
cin>>x>>y;
if(x==1 || x==2 )
cout<<“Chef\n”;

else if(x=3 && y==1)
cout<<“Divyam’\n”;
else if(x==4 && y>=2)
cout<<“Chef’\n’”;

else if(x==4 && y>=2)
cout<<“Chef’\n’”;
else if(x==4 && y==1)
cout<<“Divyam’\n’”;

else if(x==5 || x==6 && y>=3)
cout<<“Chef’\n’”;
else if(x==5 || x==6 && y<3)
cout<<“Divyam’\n’”;

}

}

Its not the case of for and while here, you commented out
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
Thats what causing your tle, however your approach is incorrect in both of the solutions.
If the number of prime numbers allowed is more than or equal to the prime number which are less then than N, then chef will win, else Divyam will win.

1 Like

@sachin0102 sorry dude i messed up
same this but (wa)

#include <algorithm> 
#include <vector>
#define ll long long int 
using namespace std; 



int main ()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 cout.tie(NULL);
ll t=0;
cin>>t;
for(int i=0; i<t; i++)
//while(t--)
{ // cout<<"Chef"<<endl;


ll x=0,y=0;
cin>>x>>y;
  if(x==1  || x==2 )
  cout<<"Chef\n";
  
  else if(x=3 && y==1)
  cout<<"Divyam'\n";
  else if(x==4 && y>=2)
  cout<<"Chef'\n'";
  
 else if(x==4 && y>=2)
 cout<<"Chef'\n'";
 else if(x==4 && y==1)
 cout<<"Divyam'\n'";
 
 else if(x==5 || x==6 && y>=3)
 cout<<"Chef'\n'";
 else if(x==5 || x==6 && y<3)
 cout<<"Divyam'\n'";
  

      
    
    
}



}
check this code and i know it's WA i am just asking about loop thing
and i can not upload link becuz. i am not getting it from my submission.
so can please put this code in your problem and check   
[https://www.codechef.com/FEB21C/problems/PRIGAME/](https://www.codechef.com/FEB21C/problems/PRIGAME/)

only difference is loop while using for loop u will not get tle. but using while (loop) u get

Using either for or while loop doesn’t really affect the time of execution that much, just for the sake of it, I’ve submitted using for as well.
Using for loop : https://www.codechef.com/viewsolution/42873675
Using while loop : https://www.codechef.com/viewsolution/42545959

1 Like

ya bro it’s nothing to do with loop .