✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.
Given the following code to compute "n to the power of x"
static int fastPower(int n, int x){
int a= x; int b= 1; int i= n;
while(i>0) {
if (i%2==0){
a= a*a;
i= i/2;
}
else {
b= a*b;
i= i-1;
}
}
return b;
}
Which of the following logical statements is a valid and useful invariant for proving this code does actually compute n to the power of x?