输出结果必须是字符串型,题目中其实有提示0023
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int isprime(int n);
int main() {
int n, k, num, flag = 0;
string s, cs;
cin >> n >> k >> s;
for(int i = 0; i < n-k+1; i++){
cs = s.substr(i, k);
if(isprime(stoi(cs))){
cout << cs;
flag = 1; break;
}
}
if(flag == 0) cout << "404";
return 0;
}
int isprime(int n){
int ans = 1;
if(n <= 1) ans = 0;
for(int i = 2; i <= sqrt(n); i++){
if( n % i == 0) ans = 0;
}
return ans;
}