forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimedrive.cpp
60 lines (54 loc) · 1.01 KB
/
primedrive.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
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void incrementplate(string& s) {
if(s[2] == 'Z') {
s[2] = 'A';
if(s[1] == 'Z') {
s[1] = 'A';
if(s[0] == 'Z') {
s[0] = 'A';
}
else {
s[0]++;
}
}
else {
s[1]++;
}
}
else {
s[2]++;
}
}
bool isprime(int n) {
if(n < 2) {
return false;
}
if(n == 2) {
return true;
}
for(int i = 2; i <= sqrt(n); i++) {
if(n % i == 0) {
return false;
}
}
return true;
}
int main() {
string s;
int n;
while(cin >> s && cin >> n && !(s == "END" && n == 0)) {
while(!isprime(n)) {
n++;
if(n == 10000) {
incrementplate(s);
n = 2;
break;
}
}
cout << setfill('0');
cout << s << " " << setw(4) << n << endl;
}
}