ソースコード
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++)
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vci vector<ll>
#define vcs vector<string>
#define vcp vector<pair<ll, ll>>
#define vct vector<tuple<ll, ll, ll>>
using namespace std;
//vector<vector<ll>> vv(n, vector<ll>(n));
typedef int Weight;
struct Edge
{
int from, to; Weight cost;
bool operator < (const Edge& e) const { return cost < e.cost; }
bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
g[from].push_back(Edge{ from, to, cost });
}
int main()
{
ll n;
cin >> n;
vci v;
FOR(i,2,n+1)
{
bool flg = true;
FOR(j, 2, sqrt(i)+1)
{
if (i%j == 0) flg = false;
}
if(flg) v.push_back(i);
}
REP(i, v.size()) cout << v[i] << (i != v.size() - 1 ? " " : "");
cout << endl;
}