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;
}