add c++ solution of #3060
This commit is contained in:
parent
31bc65ca8e
commit
0b1d62ffb5
3 changed files with 35 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -250,3 +250,4 @@ Module.symvers
|
|||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
a.out
|
||||
|
|
BIN
3060/.solutie.cpp.swp
Normal file
BIN
3060/.solutie.cpp.swp
Normal file
Binary file not shown.
34
3060/solutie.cpp
Normal file
34
3060/solutie.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int k=0, p=0, n=0, i=0;
|
||||
cin >> k;
|
||||
cin >> p;
|
||||
for (i = 9999; i >= 0; i--) {
|
||||
bool prime = true;
|
||||
for (int j = 2; j < i; j++) {
|
||||
if (i % j == 0) {
|
||||
prime = false;
|
||||
}
|
||||
}
|
||||
bool containsForbiddenNumber = false;
|
||||
if (prime) {
|
||||
int c = i;
|
||||
while (c > 0) {
|
||||
if (c % 10 == k || c % 10 == p) {
|
||||
containsForbiddenNumber = true;
|
||||
break;
|
||||
}
|
||||
c = c / 10;
|
||||
}
|
||||
}
|
||||
if (prime && !containsForbiddenNumber) {
|
||||
n = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
cout << n;
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue