Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: aleksee1
- LANG: C++14
- TASK: sprime
- */
- #include <bits/stdc++.h>
- using namespace std;
- #define dprint(v) cerr << #v"=" << v << endl //;)
- #define forr(i,a,b) for(int i=(a); i<(b); i++)
- #define forn(i,n) forr(i,0,n)
- #define dforn(i,n) for(int i=n-1; i>=0; i--)
- #define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
- #define sz(c) ((int)c.size())
- #define zero(v) memset(v, 0, sizeof(v))
- #define pb push_back
- #define fst first
- #define sec second
- #define N_MAX 10
- typedef long long ll;
- typedef pair<int,int> ii;
- typedef int tipo;
- ll n;
- vector<string> a;
- bool isPrime(ll x)
- {
- if (x % 2 == 0)
- return false;
- if (x == 1)
- return false;
- for (ll p = 3; p <= x / 2; ++p)
- if (x % p == 0)
- return false;
- return true;
- }
- int main()
- {
- //ifstream cin("sprime.in");
- //ofstream cout("sprime.out");
- ios::sync_with_stdio(0);
- cin.tie(), cout.tie();
- cin >> n;
- for (ll i = 2; i <= 7; ++i)
- if (isPrime(i))
- a.push_back(to_string(i));
- for (ll i = 1; i < n; ++i)
- {
- for (ll j = 0; j < a.size(); ++j)
- {
- ll p = stoi(a[j]);
- for (ll z = 0; z <= 9; ++z)
- {
- if (isPrime(p * 10 + z))
- a.push_back(to_string(p * 10 + z));
- }
- }
- for (ll z = 0; z < a.size(); ++z)
- if (a[z].size() < i + 1)
- a.erase(a.begin() + z);
- }
- for (ll i = 0; i < a.size(); ++i)
- cout << a[i] << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement