ch1 : Superprime Rib


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.   NAME : Nursoltan
  3.   PROB : sprime
  4.   LANG : C++
  5.   DATE : 01/07/11 15:02
  6. */
  7. #include <algorithm>
  8. #include <bitset>
  9. #include <cctype>
  10. #include <cmath>
  11. #include <cstdio>
  12. #include <cstdlib>
  13. #include <cstring>
  14. #include <ctime>
  15. #include <sstream>
  16. #include <iostream>
  17. #include <map>
  18. #include <set>
  19. #include <stack>
  20. #include <utility>
  21. #include <queue>
  22.  
  23. using namespace std;
  24.  
  25. #define MAX 100
  26. #define INF INT_MAX
  27. #define eps (1e-9)
  28.  
  29. #define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)
  30. #define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)
  31. #define CLR(_x) memset((_x),0,sizeof(_x))
  32. #define SQR(_x) ((_x)*(_x))
  33. #define all(_x) _x.begin(),_x.end()
  34. #define sz(_x) sizeof(_x)
  35.  
  36. #define vc vector<int>
  37. #define pb push_back
  38. #define mp make_pair
  39. #define iss istringstream
  40. #define oss ostringstream
  41. #define px first
  42. #define py second
  43.  
  44. typedef long long ll;
  45. typedef pair <int,int> point;
  46. int ABS(int _x){ return _x>0?_x:-_x; }
  47.  
  48. bool isPrime(int x){
  49. FOR(i,2,sqrt(x)+2) if(x%i==0) return 0;
  50. return 1;
  51. }
  52.  
  53. void rec(int N, int dig){
  54. if(dig==0){
  55. cout<<N<<endl;
  56. return;
  57. }
  58. FOR(i,1,10) if(isPrime(10*N+i)) rec(10*N+i,dig-1);
  59. }
  60.  
  61. int main()
  62. {
  63. freopen("sprime.in","r",stdin);
  64. freopen("sprime.out","w",stdout);
  65.  
  66. int N;
  67. cin>>N;
  68.  
  69. rec(2,N-1);
  70. rec(3,N-1);
  71. rec(5,N-1);
  72. rec(7,N-1);
  73.  
  74. //system("pause");
  75. return 0;
  76. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.