Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. /*
  2. ID: aleksee1
  3. LANG: C++14
  4. TASK: sprime
  5. */
  6. #include <bits/stdc++.h>
  7. using namespace std;
  8. #define dprint(v) cerr << #v"=" << v << endl //;)
  9. #define forr(i,a,b) for(int i=(a); i<(b); i++)
  10. #define forn(i,n) forr(i,0,n)
  11. #define dforn(i,n) for(int i=n-1; i>=0; i--)
  12. #define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
  13. #define sz(c) ((int)c.size())
  14. #define zero(v) memset(v, 0, sizeof(v))
  15. #define pb push_back
  16. #define fst first
  17. #define sec second
  18. #define N_MAX 10
  19. typedef long long ll;
  20. typedef pair<int,int> ii;
  21. typedef int tipo;
  22.  
  23.  
  24. ll n;
  25.  
  26. vector<string> a;
  27.  
  28. bool isPrime(ll x)
  29. {
  30. if (x % 2 == 0)
  31. return false;
  32. if (x == 1)
  33. return false;
  34. for (ll p = 3; p <= x / 2; ++p)
  35. if (x % p == 0)
  36. return false;
  37. return true;
  38. }
  39.  
  40.  
  41.  
  42. int main()
  43. {
  44. //ifstream cin("sprime.in");
  45. //ofstream cout("sprime.out");
  46.  
  47. ios::sync_with_stdio(0);
  48. cin.tie(), cout.tie();
  49.  
  50. cin >> n;
  51.  
  52. for (ll i = 2; i <= 7; ++i)
  53. if (isPrime(i))
  54. a.push_back(to_string(i));
  55.  
  56. for (ll i = 1; i < n; ++i)
  57. {
  58. for (ll j = 0; j < a.size(); ++j)
  59. {
  60. ll p = stoi(a[j]);
  61. for (ll z = 0; z <= 9; ++z)
  62. {
  63. if (isPrime(p * 10 + z))
  64. a.push_back(to_string(p * 10 + z));
  65. }
  66. }
  67. for (ll z = 0; z < a.size(); ++z)
  68. if (a[z].size() < i + 1)
  69. a.erase(a.begin() + z);
  70. }
  71.  
  72. for (ll i = 0; i < a.size(); ++i)
  73. cout << a[i] << "\n";
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement