-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14.cpp
More file actions
51 lines (38 loc) · 818 Bytes
/
14.cpp
File metadata and controls
51 lines (38 loc) · 818 Bytes
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 <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
bool isPrime(int num) {
//std::cout << num << "\n";
if(num % 2 == 0)
return false;
for(int i = 3; i <= static_cast<int>(sqrt(num)); i+=2) {
if(num % i == 0)
return false;
}
return true;
}
int main() {
int numPas;
std::string ticketNum;
std::cin >> numPas >> ticketNum;
int startFrom = atoi(ticketNum.c_str());
int notMoreThan = pow(10, ticketNum.size());
//std::cout << notMoreThan << " " << startFrom << "\n";
bool found = false;
int i;
for(i = 1; i < numPas; i++) {
int currentTicket = startFrom + i;
if(currentTicket >= notMoreThan)
break;
found = isPrime(currentTicket);
if(found)
break;
}
if(found) {
std::cout << i - 1 << "\n";
} else {
std::cout << -1 << "\n";
}
return 0;
}