Created
March 22, 2020 15:53
-
-
Save niklasjang/c06fbd3b76ae7a3e76cdc1811abd1d17 to your computer and use it in GitHub Desktop.
[PS][완전탐색][N자리 K진수]/[BOJ][2023][신기한 소수]
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; | |
int n=0; | |
bool isPrime(int num){ | |
if(num == 0) return true; | |
if(num == 1) return false; | |
int cnt = 0; | |
for(int i=1; i*i<=num; i++){ | |
if(num %i == 0){ | |
cnt++; | |
} | |
} | |
return cnt == 1; | |
} | |
void recur(int depth, int curr){ | |
if(!isPrime(curr)) return; | |
if(depth == n){ | |
cout<< curr<<'\n'; | |
return; | |
} | |
for(int i=1; i<10; i++){ | |
recur(depth+1,curr*10+i); | |
} | |
} | |
int main (void){ | |
cin.tie(NULL); | |
ios::sync_with_stdio("false"); | |
cin>> n; | |
recur(0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment