-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14.cpp
40 lines (40 loc) · 774 Bytes
/
14.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
#include <iostream>
#include <string>
#include <math.h>
#include <sstream>
using namespace std;
int main()
{
int N, ans=-1;
bool fail=false, found=false;
long tick;
short len;
string ticket;
cin >> N >> ticket;
stringstream ss(ticket);
ss >>tick;
len=(short)ticket.length();
ticket="";
for(long i=tick+1; i<tick+N; ++i, fail=false) {
ss.str("");
ss.clear();
ss << i;
ticket = ss.str();
if(len<(short)ticket.length()){
fail=true;
break;
}
++ans;
for(int j=2; j<=sqrt(i); ++j) {
if(!(i%j)) {
fail=true;
}
}
if(!fail) {
found=true;
break;
}
}
cout << (fail||!found ? -1: ans)<<endl;
return 0;
}