Skip to content

Instantly share code, notes, and snippets.

@niklasjang
Created March 22, 2020 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niklasjang/c06fbd3b76ae7a3e76cdc1811abd1d17 to your computer and use it in GitHub Desktop.
Save niklasjang/c06fbd3b76ae7a3e76cdc1811abd1d17 to your computer and use it in GitHub Desktop.
[PS][완전탐색][N자리 K진수]/[BOJ][2023][신기한 소수]
#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