CF894C 题解
思路
我们设 ,然后我们只要构造一个类似 就行了,长度 (反正限制只有 ,够用了)。另外如果 不在 里就是无解。
代码
# include <bits/stdc++.h>
using namespace std;
int n, a[1005], g;
int main () {
ios::sync_with_stdio (0);
cin.tie (0);
cout.tie (0);
cin >> n;
for (int i = 0; i < n; ++ i)
cin >> a[i], g = __gcd (g, a[i]);
for (int i = 0; i < n; ++ i)
if (a[i] == g)
goto there;
cout << "-1";
return 0;
there:
;
cout << n * 2 << '\n';
for (int i = 0; i < n; ++ i)
cout << g << ' ' << a[i] << ' ';
return 0;
}

浙公网安备 33010602011771号