题目
题意:
给你一个数字 ,现在你需要将 ~ 中的数字放入 中,从两个开始放,每次放一个,最后要使每一个的两两之间的最大的 最小,输出每次的 。
思路:
因为每次的 最大的要最小,所以我们刚开始可以放素数进去,这样两两之间就都是 ,然后再放入 的倍数, 的倍数…,这样我们就可以用埃式筛法求出每一个数字的最大因子。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1:1;
ret = (c == '-') ? 0:(c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return ;
}
inline void out(int x) {
if (x > 9) out(x / 10);
putchar(x % 10 + '0');
}
const int maxn = 5e5 + 10;
int a[maxn] = {0};
void init() {
for (int i = 1; i < maxn; i++) {
for (int j = 2 * i; j < maxn; j += i) {
a[j] = i;
}
}
}
int main() {
init();
int n;
read(n);
sort(a + 2, a + n + 1);
for (int i = 2; i <= n; i++) {
printf("%d ", a[i]);
}
return 0;
}