Find CB number- please

#include <bits/stdc++.h>
using namespace std;

bool mycompare(string a,string b){
return a.length()<b.length();
}

bool checkcb(string s,int* number){
if(s == "0" || s== "1"  ){
    return false;
}
else if(s=="2"||s=="3"||s=="5"||s=="7"||s=="11"||s=="13"||s=="17"||s=="19"||s=="23"||s=="29"){
    return true;
}
int x=stoi(s);
for(int i=0;i<10;i++){
    if((x%number[i]) == 0){
        return false;
    }
}
return true;
}
bool ans[10]={false};
bool isvalid(string s){
int x=stoi(s);
while(x!=0){
    int temp=x%10;
    if(ans[temp]==1){
        return false;
    }
    x=x/10;
}
return true;
}
int main(){
   int n;
   cin>>n;
   string s;
   cin>>s;
   vector<string>v ;
for (int i = 0; i < n; i++){ 
    for (int len = 1; len <= n-i; len++){
        v.push_back(s.substr(i, len));
    }
}
sort(v.begin(),v.end(),mycompare);
 
int number[]={2,3,5,7,11,13,17,19,23,29};
int count=0;
for(int i=0;i<v.size();i++){
    if(checkcb(v[i],number) && isvalid(v[i])){
        count++;
        //cout<<v[i]<<endl;
        int x=stoi(v[i]);
        while(x!=0){
        int temp=x%10;
        ans[temp]=1;
        x=x/10;
                    }
        
    }
  
}
    cout<<count<<endl;

	return 0;
}

can anyone please help correct my code, I think I am logically correct, by first sorting the substrings in increasing order and then checking its validity, but it is not working.!


This is the code you can refer to for your solution, explanation is present in the beginning of code, kindly use it for your reference solution

@yuktimutreja01

hey, please tell the mistake in my code. i am following the same approach but getting wrong ans.