Skip to content

Commit

Permalink
Create 1152. Google Recruitment (20).cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchuo committed Dec 28, 2018
1 parent 6da015e commit dbd377b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions AdvancedLevel_C++/1152. Google Recruitment (20).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <string>
using namespace std;
bool isPrime(int n) {
if (n == 0 || n == 1) return false;
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return false;
return true;
}
int main() {
int l, k;
string s;
cin >> l >> k >> s;
for (int i = 0; i <= l - k; i++) {
string t = s.substr(i, k);
int num = stoi(t);
if (isPrime(num)) {
cout << t;
return 0;
}
}
cout << "404\n";
return 0;
}

1 comment on commit dbd377b

@newcaoguo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks extremely good and thank you for contribution. 👍

Please sign in to comment.