Created
July 18, 2016 05:37
-
-
Save beomkm/2e98e7b9d2377359de6d78a02b3cc333 to your computer and use it in GitHub Desktop.
kut1010
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool isPrime(int n) | |
{ | |
//omit 1 | |
for (int i = 2; i*i <= n; i++) { | |
if (n%i == 0) return false; | |
} | |
return true; | |
} | |
void print(int n, int digit) | |
{ | |
if (digit==1) { | |
cout << n << endl; | |
return; | |
} | |
n *= 10; | |
for (int i = 1; i < 10; i += 2) { | |
if (i == 5) continue; | |
if (isPrime(n + i)) { | |
print(n + i, digit-1); | |
} | |
} | |
} | |
int main(void) | |
{ | |
int digit; | |
cin >> digit; | |
print(2, digit); | |
print(3, digit); | |
print(5, digit); | |
print(7, digit); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment