import scala.io.StdIn

object Main {

  def divisors(n: Int): Vector[Int] = {
    def rec(i: Int, acc: Vector[Int]): Vector[Int] = {
      if (i * i > n) acc
      else if (i * i == n) acc :+ i
      else if (n % i == 0) rec(i + 1, i +: acc :+ (n / i))
      else rec(i + 1, acc)
    }
    rec(1, Vector.empty[Int])
  }

  def switch(as: Vector[Int], n: Int): Vector[Int] = {
    divisors(n).foldLeft(as)((acc, d) => as.updated(d, 1 - as(d)))
  }

  def solve(as: Vector[Int], n: Int): Vector[Int] = {
     if (n == 0) Vector(0)
     else {
       if (as(n) == 0) {
         solve(as.dropRight(1), n - 1) :+ 0
       } else {
         solve(switch(as, n), n - 1) :+ 1
       }
     }
  }

  def main(args: Array[String]): Unit = {
     val n = StdIn.readInt()
     val as = 0 +: StdIn.readLine().split(' ').map(_.toInt).toVector
     val bs = solve(as, n)
  }

}