Hey there!
Can you suggest how I can optimize my code.
It is giving wrong answer for test case 1 and time limit for the second. It works fine on the sample test case.
#include<bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
v.push_back(2);
v.push_back(3);
v.push_back(5);
v.push_back(7);
v.push_back(11);
v.push_back(13);
v.push_back(17);
v.push_back(19);
int t;
cin>>t;
t++;
while(t--)
{
int n;
cin>>n;
int ans=0;
for (int i=0; i<n; i++)
{
bool flag= false;
for (int j=0; j<8; j++)
{
if(i % v[j]==0)
{
flag=true;
}
}
if (flag==true)
{
ans++;
}
}
cout<<ans<<"\n";
}
return 0;
}