Suppose π = β©π[0], β¦ , π[π β 1]βͺ is an array of length π, where all theβ¦
2015
Suppose π = β©π[0], β¦ , π[π β 1]βͺ is an array of length π, where all the entries are from the set {0, 1}. For any positive integers π and π, consider the following pseudocode.

If π = 4, π = β©1, 0, 1, 1βͺ, π = 2 and π = 8, then the output of DOSOMETHING(π, π, π) is __________________.
Attempted by 45 students.
Show answer & explanation
Correct answer: 0
Step-by-step evaluation:
Initialize z = 1.
i = 0: square z: 1^2 mod 8 = 1. Since c[0] = 1, multiply by a: 1 Γ 2 mod 8 = 2. Resulting z = 2.
i = 1: square z: 2^2 mod 8 = 4. Since c[1] = 0, do not multiply. Resulting z = 4.
i = 2: square z: 4^2 = 16 mod 8 = 0. Since c[2] = 1, multiply by a: 0 Γ 2 mod 8 = 0. Resulting z = 0.
i = 3: square z: 0^2 = 0 mod 8 = 0. Since c[3] = 1, multiply by a: 0 Γ 2 mod 8 = 0. Resulting z = 0.
Return value: 0