fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int oo = 1e3 + 3;
  5.  
  6. int n;
  7. int a[oo];
  8.  
  9. int main() {
  10.  
  11. cin >> n;
  12. for (int i = 1; i <= n; i++) {
  13. cin >> a[i];
  14. }
  15.  
  16. vector<int>v;
  17. int cnt = 0;
  18.  
  19. v.push_back(a[1]);
  20. for (int i = 2; i <= n; i++) {
  21. if (__gcd(a[i], v.back()) != 1) {
  22. v.push_back(1);
  23. cnt++;
  24. }
  25.  
  26. v.push_back(a[i]);
  27. }
  28.  
  29. cout << cnt << "\n";
  30. for (auto &x : v) {
  31. cout << x <<" ";
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 544KB
stdin
3
2 7 28
stdout
1
2 7 1 28