GATE 2015 CS (CS3) – Question 63
Find DOSOMETHING(c,a,n) for k=4,c=(1,0,1,1),a=2,n=8.
z=1
for i=0 to k−1:
z=z² mod n
if c[i]==1: z=(z*a) mod n
return zPractise this question in The GATE Grind →
Show answer and explanation
Correct answer: 0
Explanation
Start z=1. At i=0, square then multiply by two, yielding two. At i=1, square to four with no multiply. At i=2, square four modulo eight to zero, then multiply, remaining zero. The final iteration also leaves zero. Thus the returned value is zero.