特判1 2 3这些数据就行,因为后面的数据不需要改变,第i个就是i,i+i=2i,肯定不是质数。
#include <iostream> #include <queue> #include <map> #include <set> #include <cmath> #include <cstring> #include <algorithm> #include <iomanip> #include <stack> #include <numeric> #include <ctime> #include <string> #include <bitset> #include <unordered_map> #include <unordered_set> using namespace std; using ll = long long; const ll N = 1e6 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f; int n; void solve() { cin >> n; if (n <= 2) { cout << -1 << '\n'; return ; } cout << 3 << " " << 2 << " " << 1 << " "; for (int i = 4; i <= n; i++) { cout << i << " "; } } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; //cin>>t; while (t--) { solve(); } return 0; }