-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12542 - Prime Substring.cpp
51 lines (44 loc) · 998 Bytes
/
12542 - Prime Substring.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
int pri (int n)
{
int sq = sqrt(n);
for(int i = 2; i <= sq; i++)
{
if(n % i == 0)
return 0;
}
return 1;
}
int main()
{
string s;
while(cin >> s)
{
if(s == "0")
break;
string temp;
vector <int> v;
for(int i = 0; i < s.size(); i++)
{
for(int j = i; s[j]; j++ )
{
if(j == i + 6)
break;
temp += s[j];
int ans = 0;
for(int p = 0; p < temp.size(); p++)
{
ans = ans * 10 + temp[p] - '0';
}
if(pri(ans) == 1 && ans != 1 && ans != 0 && ans <= 100000)
v.push_back(ans);
}
temp.clear();
}
vector <int> :: iterator it;
it = max_element(v.begin(), v.end());
cout<<*it<< endl;
}
return 0;
}