Language: C++

#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


void solve() {
    int N;
    cin >> N;
    vector<int> v(N);
    vector<int> balls(N);

    REP(i,N) cin >> v[i];
    REPR(i,N-1) {
        auto t = i + (i+1);
        auto sm = 0;
        while(t < N) {
            sm += balls[t];
            t += (i+1);
        }
        if(sm%2 != v[i]) balls[i] = 1;
    }
    auto sum = accumulate(ALL(balls),0);

    cout << sum << endl;
    vector<int> ans;
    REP(i,N) if(v[i]!=0) ans.push_back(i+1);
    ostringstream os;
    copy(ALL(v),ostream_iterator<string>(os," "));

    cout << os.str() << endl;

}

int main() {
    solve();
    return 0;
}


Compiler output:
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = int*; _OI = std::ostream_iterator<std::__cxx11::basic_string<char> >]':
/usr/include/c++/14/bits/stl_algobase.h:521:30:   required from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = int*; _OI = ostream_iterator<__cxx11::basic_string<char> >]'
  520 |       return std::__copy_move<_IsMove, __memcpyable<_OI, _II>::__value,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  521 |                               _Category>::__copy_m(__first, __last, __result);
      |                               ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:548:42:   required from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = int*; _OI = ostream_iterator<__cxx11::basic_string<char> >]'
  548 |     { return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:556:31:   required from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<int*, vector<int> >; _OI = ostream_iterator<__cxx11::basic_string<char> >]'
  556 |                 std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  557 |                                              std::__niter_base(__last),
      |                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~
  558 |                                              std::__niter_base(__result)));
      |                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:651:7:   required from '_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<int*, vector<int> >; _OI = ostream_iterator<__cxx11::basic_string<char> >]'
  650 |       return std::__copy_move_a<__is_move_iterator<_II>::__value>
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  651 |              (std::__miter_base(__first), std::__miter_base(__last), __result);
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:40:9:   required from here
   40 |     copy(ALL(v),ostream_iterator<string>(os," "));
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:403:25: error: no match for 'operator=' (operand types are 'std::ostream_iterator<std::__cxx11::basic_string<char> >' and 'int')
  403 |               *__result = *__first;
      |               ~~~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/iterator:65,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/stream_iterator.h:237:25: note: candidate: 'constexpr std::ostream_iterator<_Tp, _CharT, _Traits>& std::ostream_iterator<_Tp, _CharT, _Traits>::operator=(const std::ostream_iterator<_Tp, _CharT, _Traits>&) [with _Tp = std::__cxx11::basic_string<char>; _CharT = char; _Traits = std::char_traits<char>]'
  237 |       ostream_iterator& operator=(const ostream_iterator&) = default;
      |                         ^~~~~~~~
/usr/include/c++/14/bits/stream_iterator.h:237:35: note:   no known conversion for argument 1 from 'int' to 'const std::ostream_iterator<std::__cxx11::basic_string<char> >&'
  237 |       ostream_iterator& operator=(const ostream_iterator&) = default;
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stream_iterator.h:243:7: note: candidate: 'std::ostream_iterator<_Tp, _CharT, _Traits>& std::ostream_iterator<_Tp, _CharT, _Traits>::operator=(const _Tp&) [with _Tp = std::__cxx11::basic_string<char>; _CharT = char; _Traits = std::char_traits<char>]'
  243 |       operator=(const _Tp& __value)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stream_iterator.h:243:28: note:   no known conversion for argument 1 from 'int' to 'const std::__cxx11::basic_string<char>&'
  243 |       operator=(const _Tp& __value)
      |                 ~~~~~~~~~~~^~~~~~~