Unable to solve this error

hello, i am unable to solve this error : terminate called after throwing an instance of ‘std::invalid_argument’
what(): stoi
/bin/run.sh: line 4:18 Aborted (core dumped) ./exe
My code :

#include
#include
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int a){
if(a == 1 || a == 0) return false;
if(a == 2) return true;
for(int i=2;i<=sqrt(a);i++){
if(a % i == 0){
return false;
}
}
return true;
}
int main() {
int n;
cin>>n;
string s;
cin>>s;
int cbmax;
vector prime={2,3,5,7,11,13,17,19,23,29};
for(int i=0;i<n;i++) {
int cb=0;
for(int j=0;j<n;j++){
int num = stoi(s.substr(j,i+j));
if(isPrime(num)) cb++;
}
cbmax=max(cb,cbmax);
}
cout<<cbmax;
return 0;
}

this is because the string you want to convert into integer is invalid

for i=0,j=0

s.substr(0,0) will give you empty string which cann’t be converted to integer that’s why it is throwing an error

correct way

int num = stoi(s.substr(j,i+j+1));

okay, I got that. s.substr(0,0) means empty string but also s.substr(1,1) means substring with value s[1]. I didn’t get this. May be i have to think again about the logic.

s.substr(1,1) means substring of string starting form index 1 of the length one
it is okay

problem with your logic try to think now