Finding cb numbers


why TLE

Hi Sakshi
Your earlier submission ran successfully on 31st March. What changes did you make?

#include<iostream>
using namespace std;
bool check(int num)
{
int a[]={2,3,5,7,11,13,17,19,23,29};
if(num==0||num==1)
return 0;
if(num>=31)
{
	for(int i=0;i<10;i++)
	{
		if(num%a[i]==0)
		return 0;
	}
	return 1;
}
else 
{
	for(int i=0;i<10;i++)
	{
		if(num==a[i])
		return 1;
	}
	return 0;
}
return 1;
}
bool vis(bool * dp,int i,int j)
{
	for(int h =i;h<=j;h++)
	{
		if(dp[h])
		return 1;
	}
	return 0;
}
int main() {
	int n;
	string s;
	cin>>n;
	cin>>s;
//	cout<<s;
	int count=0;
	int num=0;
	bool dp[n]={0};
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n-i;j++)
		{
			num=0;
			int h=j;
			while(h<=j+i)
			{
				num=num*10+(s[h]-'0');
				h++;
				if(check(num)&&!vis(dp,j,j+i))
				{count++;
				for(h=j;h<=j+i;h++)
				dp[h]=1;
				}
			}
		}
	}
	cout<<count<<endl;
	return 0;
}

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.