#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
bool isprime(string s) {
int n = stoi(s);
if (n == 1)return false;
for (int i = 2; i <=sqrt(n); i++) {
if (n % i == 0)
return false;
}
return true;
}
int main() {
//L (≤ 1,000) and K (< 10)
int l, k;
cin >> l >>k;
string str;
cin >> str;
//2468024680
//0123456789
//l-k=10-3=7
bool flag = false;
for (int i = 0; i <=l - k; i++) {
string tmp=str.substr(i, k);
if (isprime(tmp)) {
cout << tmp;
//prt(tmp);
flag = true;
break;
}
}
if (flag == false)
cout << 404;
return 0;
}
|素数判断&stoi字符串转int&str.substr(index,length)&第一个break|18冬第一题1152 Google Recruitment (20分)
最新推荐文章于 2024-03-10 14:37:34 发布