题目描述
分析:截取字符串,判断是否是素数
C++字符串转换(stoi;stol;stoul;stoll;stoull;stof;stod;stold)
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
bool isPrime(ll n){
if(n<2){
return false;
}
for(ll i=2;i<=(ll)sqrt(n);i++){
if(n%i==0){
return false;
}
}
return true;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll L,K;
string str;
cin>>L>>K>>str;
for(int i=0;i<str.length()-K+1;i++){
string temp=str.substr(i,K);
if(isPrime(stoll(temp))){
cout<<temp<<endl;
return 0;
}
}
cout<<"404"<<endl;
}