素数判断,暴力搜索
string.substr(start,len); //参数分别是开始位置,和截取字串长度。
数字转字符串 to_string(int value);
字符串转数字 stoi(string str);
stol(string str);
stof(string str);
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
bool IsPrime(int a);
int main()
{
int n, k;
string s;
cin >> n >> k;
cin >> s;
int l = s.length();
bool flag = false;
for (int i = 0; i+k-1 < l; i++)
{
string str;
int a;
str = s.substr(i, k);
a = stoi(str);
if (a > 0)
{
if (IsPrime(a))
{
flag = true;
cout << str << endl;
break;
}
}
}
if (!flag)
cout << "404" << endl;
system("pause");
return 0;
}
bool IsPrime(int a)
{
for (int i = 2; i <= sqrt(a); i++)
{
if (a%i == 0)
return false;
}
return true;
}