简单构造。
n=2 显然不存在一组数 a 和 b 使得 \operatorname{lcm}(a,b)=\lvert a-b\rvert。
n=3 时 1,3,6 是一组解,其差分绝对值序列是 2,3,两个序列的 \operatorname{lcm} 都是 6。
考虑 n>3。注意到在序列末尾插入一个已经在序列中的数,序列的 \operatorname{lcm} 不变。因此可以在 1,3,6 后面交替插入 3 和 6,得到序列 1,3,6,3,6,\ldots,其差分绝对值序列是 2,3,3,3,\ldots,\operatorname{lcm} 都是 6。
时间复杂度 O(n) 。
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(n==2)cout<<-1;
else{
cout<<"1 3 6 ";
for(int i=4;i<=n;i++){
if(i%2)cout<<"6 ";
else cout<<"3 ";
}
}
}