What is issue in my code?

#include
#include
#include<math.h>
using namespace std;

bool prime(int a)
{
if(a==0 or a==1)
return false;

else if(a==2)
return true;

for(int i=2;i<=sqrt(a);i++)
if(a%i==0)
return false;

return true;

}

int convert_to_int(int i,int j,char ch[])
{
int factor=j-i;
int sum=0;
for(int k=i;k<=j;k++)
{

	sum=sum+(ch[k]-'0')*pow(10,factor);
	factor--;
}
return sum;

}

int count_it(char ch[],int n)
{
int count=0;
int k=0;
int t;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{t=convert_to_int(i,j,ch);
if(prime(t))
{count++;i=j;break;}

	}
	cout<<endl;
}
return count;

}

int main()
{
int n;
cin>>n;
cin.ignore();

char ch[n+1];
cin.getline(ch,n+1);

cout<<count_it(ch,n)<<endl;

}

Hi @Nidhi_Alipuria, It is possible that the number is not prime number but still a CB Number
eg (59*59), or any number which have every prime factors greater than 29
refer this discussion :- Why all the test cases are not passing?

In case of any doubt feel free to ask :slight_smile:
mark your doubt as resolved if you got the answer

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.