Getting tle in one test case

kindly help me out to optimise my code.

#include<bits/stdc++.h>
using namespace std;
int main() {
int t; cin>>t;
long long int n;

while(t--)
{  
	 
	 cin>>n;
     int res=0;
	 for(int i=2;i<=n;i++)
	 {
		 if(i%2==0 || i%3==0 || i%5==0 || i%7==0 || i%9==0 || i%11==0 || i%13==0 || i%15==0 || i%17==0 || i%19==0)
		 {
			 res++;
		 }
	 }
	 cout<<res<<endl;

}

return 0;

}

Hello @raj_pareek please wait i am checking your code.

Hello @raj_pareek
This question is based on inclusion exclusion principle (Set theory)
let a,b,c,d,e,f… represent set of prime numbers less than 20.

Now you have to find
a union b union c union d…

this can be found by inclusion exclusion principle.

In case you need explanation do post it.

got it, i will try and get back to you asap if get any issue,thanks!!

@raj_pareek yes you should try and incase you are unable to think then you can see this video of prateek sir:


Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.