Language: C++

#include<bits/stdc++.h>
#define FOR(i,n,m) for(int i = m;i<n;i++)
#define rep(i,n) FOR(i,n,0)
#define ll long long
#define INF (1e9)
#define PI (acos(-1))
int dy[] = { 0, 0, 1, -1 };
int dx[] = { 1, -1, 0, 0 };
using namespace std;
int n;
int ans[55];
bool sosuu[10000000];
void Eratosthenes() {
	for (int i = 0; i < 10000000; i++) {
		sosuu[i] = true;
	}
	sosuu[0] = sosuu[1] = false;
	for (int i = 2; i < sqrt(10000000); i++) {
		if (sosuu[i]) {
			for (int j = 0; i * (j + 2) < 10000000; j++) {
				sosuu[i *(j + 2)] = false;
			}
		}
	}
}
int com[5][3478761];
int count = 0; // 組合せの総数

			   // 実際に組合せを生成する
			   // comb: 生成された組合せ配列
			   // step: n桁目までが生成されていることを示す。
			   // init: その桁始まりの数を示す。
void makeCombination(vector<int> comb, int n, int r, int step, int init) {
	// r桁すべてが生成された
	if (step == r) {
		for (int j = 0; j < r; ++j) {
			com[j][count] = comb[j];
		}
		++count;
		return;
	}

	// 全桁生成されていない
	for (int i = init; i <= n - r + step; ++i) {
		comb.push_back(i);
		makeCombination(comb, n, r, step + 1, i + 1);
		// ここで配列から一つ排除しないと困ったことになる
		comb.pop_back();
	}
}

// makeCombinationに値を渡すためだけの関数
// n個の中からr個選択する
void combination(int n, int r) {
	vector<int> comb;
	makeCombination(comb, n, r, 0, 0);
}
bool check(int num) {
	combination(num, 5);
	for (i, count) {
		if (sosuu[ans[com[0][count]] + ans[com[1][count]] + ans[com[2][count]] + ans[com[3][count]] + ans[com[4][count]] == true)return false;
	}
	return true;
}



int main() {
	Eratosthenes();
	int nowpos = 0;
	cin >> n;
	rep(i, 10000000){
		if (sosuu[i]) {
			ans[nowpos] = i;
			nowpos++;
			sosuu[i] = false;
		}
		if (nowpos == 4)break;
	}
	rep(i, 10000000) {
		if (sosuu[i]) {
			ans[nowpos] = i;
			if (check(nowpos) ){
				ans[nowpos] = i;
				nowpos++;
			}
			if (nowpos == n)break;
		}
	}
	rep(i, n - 1)cout << ans[i] << " ";
	cout << ans[n - 1] << endl;
	return 0;
}


Compiler output:
a.cc: In function 'void makeCombination(std::vector<int>, int, int, int, int)':
a.cc:37:32: error: reference to 'count' is ambiguous
   37 |                         com[j][count] = comb[j];
      |                                ^~~~~
In file included from /usr/include/c++/14/algorithm:86,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:27:5: note:                 'int count'
   27 | int count = 0; // 組合せの総数
      |     ^~~~~
a.cc:39:19: error: reference to 'count' is ambiguous
   39 |                 ++count;
      |                   ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:27:5: note:                 'int count'
   27 | int count = 0; // 組合せの総数
      |     ^~~~~
a.cc: In function 'bool check(int)':
a.cc:60:14: error: 'i' was not declared in this scope
   60 |         for (i, count) {
      |              ^
a.cc:60:17: error: reference to 'count' is ambiguous
   60 |         for (i, count) {
      |                 ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:27:5: note:                 'int count'
   27 | int count = 0; // 組合せの総数
      |     ^~~~~
a.cc:63:9: error: expected primary-expression before 'return'
   63 |         return true;
      |         ^~~~~~
a.cc:62:10: error: expected ';' before 'return'
   62 |         }
      |          ^
      |          ;
   63 |         return true;
      |         ~~~~~~
a.cc:63:9: error: expected primary-expression before 'return'
   63 |         return true;
      |         ^~~~~~
a.cc:62:10: error: expected ')' before 'return'
   62 |         }
      |          ^
      |          )
   63 |         return true;
      |         ~~~~~~
a.cc:60:13: note: to match this '('
   60 |         for (i, count) {
      |             ^
a.cc:64:1: warning: control reaches end of non-void function [-Wreturn-type]
   64 | }
      | ^