/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* NAME : Nursoltan PROB : sprime LANG : C++ DATE : 01/07/11 15:02 */ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <sstream> #include <iostream> #include <map> #include <set> #include <stack> #include <utility> #include <queue> using namespace std; #define MAX 100 #define INF INT_MAX #define eps (1e-9) #define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++) #define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--) #define CLR(_x) memset((_x),0,sizeof(_x)) #define SQR(_x) ((_x)*(_x)) #define all(_x) _x.begin(),_x.end() #define sz(_x) sizeof(_x) #define vc vector<int> #define pb push_back #define mp make_pair #define iss istringstream #define oss ostringstream #define px first #define py second typedef long long ll; typedef pair <int,int> point; int ABS(int _x){ return _x>0?_x:-_x; } bool isPrime(int x){ FOR(i,2,sqrt(x)+2) if(x%i==0) return 0; return 1; } void rec(int N, int dig){ if(dig==0){ cout<<N<<endl; return; } FOR(i,1,10) if(isPrime(10*N+i)) rec(10*N+i,dig-1); } int main() { freopen("sprime.in","r",stdin); freopen("sprime.out","w",stdout); int N; cin>>N; rec(2,N-1); rec(3,N-1); rec(5,N-1); rec(7,N-1); //system("pause"); return 0; }