Posted By

Nursoltan on 07/01/11


Tagged

USACO


Versions (?)

ch1 : Prime Palindromes


 / Published in: C++
 

  1. /*
  2.   NAME : Nursoltan
  3.   PROB : pprime
  4.   LANG : C++
  5.   DATE : 01/07/11 14:35
  6. */
  7.  
  8. #include <algorithm>
  9. #include <bitset>
  10. #include <cctype>
  11. #include <cmath>
  12. #include <cstdio>
  13. #include <cstdlib>
  14. #include <cstring>
  15. #include <ctime>
  16. #include <sstream>
  17. #include <iostream>
  18. #include <map>
  19. #include <set>
  20. #include <stack>
  21. #include <utility>
  22. #include <queue>
  23.  
  24. using namespace std;
  25.  
  26. #define MAX 100
  27. #define INF INT_MAX
  28. #define eps (1e-9)
  29.  
  30. #define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)
  31. #define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)
  32. #define CLR(_x) memset((_x),0,sizeof(_x))
  33. #define SQR(_x) ((_x)*(_x))
  34. #define all(_x) _x.begin(),_x.end()
  35. #define sz(_x) sizeof(_x)
  36.  
  37. #define vc vector<int>
  38. #define pb push_back
  39. #define mp make_pair
  40. #define iss istringstream
  41. #define oss ostringstream
  42. #define px first
  43. #define py second
  44.  
  45. typedef long long ll;
  46. typedef pair <int,int> point;
  47. int ABS(int _x){ return _x>0?_x:-_x; }
  48.  
  49. int a,b;
  50.  
  51. bool isPrime(int x){
  52. if(x<a || x>b) return 0;
  53. FOR(i,2,sqrt(x)+2) if(x%i==0) return 0;
  54. return 1;
  55. }
  56.  
  57. int main()
  58. {
  59. freopen("pprime.in","r",stdin);
  60. freopen("pprime.out","w",stdout);
  61.  
  62. cin>>a>>b;
  63.  
  64. for(int d1=1; d1<10; d1+=2){
  65. int x=d1;
  66. if(isPrime(x)) cout<<x<<endl;
  67. }
  68. for(int d1=1; d1<10; d1+=2){
  69. int x=10*d1+d1;
  70. if(isPrime(x)) cout<<x<<endl;
  71. }
  72. for(int d1=1; d1<10; d1+=2) FOR(d2,0,10){
  73. int x=100*d1+10*d2+d1;
  74. if(isPrime(x)) cout<<x<<endl;
  75. }
  76. for(int d1=1; d1<10; d1+=2) FOR(d2,0,10){
  77. int x=1000*d1+100*d2+10*d2+d1;
  78. if(isPrime(x)) cout<<x<<endl;
  79. }
  80. for(int d1=1; d1<10; d1+=2) FOR(d2,0,10) FOR(d3,0,10){
  81. int x=10000*d1+1000*d2+100*d3+10*d2+d1;
  82. if(isPrime(x)) cout<<x<<endl;
  83. }
  84. for(int d1=1; d1<10; d1+=2) FOR(d2,0,10) FOR(d3,0,10){
  85. int x=100000*d1+10000*d2+1000*d3+100*d3+10*d2+d1;
  86. if(isPrime(x)) cout<<x<<endl;
  87. }
  88.  
  89. for(int d1=1; d1<10; d1+=2) FOR(d2,0,10) FOR(d3,0,10) FOR(d4,0,10){
  90. int x=1000000*d1+100000*d2+10000*d3+1000*d4+100*d3+10*d2+d1;
  91. if(isPrime(x)) cout<<x<<endl;
  92. }
  93. for(int d1=1; d1<10; d1+=2) FOR(d2,0,10) FOR(d3,0,10) FOR(d4,0,10){
  94. int x=10000000*d1+1000000*d2+100000*d3+10000*d4+1000*d4+100*d3+10*d2+d1;
  95. if(isPrime(x)) cout<<x<<endl;
  96. }
  97.  
  98. //system("pause");
  99. return 0;
  100. }

Report this snippet  

You need to login to post a comment.