A ^ B algorithm
To solve the
Below is the information:
Fast algorithm
A ^ BThe B with binary representation:
For example if: B=101011
B=2 2 ^ ^ 5 + 3 + 2 + 2 ^ ^ 1 0
A ^ B=A ^ 2 ^ (5) * A ^ 2 ^ (3) * A ^ A ^ 2 ^ (1) * (2 ^ 0)
=A ^ (2 ^ 2 ^ 3 + 5 + 2 + 2 ^ ^ 1 0)=A ^ B
So you can begin from B's low, circulation and calculate A ^ 2 ^ (0), A ^ 2 ^ (1), A ^ (2 ^ 2)...
At the same time, and to determine whether A B of the bit is 1, if is 1, the current calculation of A ^ 2 ^ (I) multiplicative to results,
I don't understand so superior solution of the algorithm
CodePudding user response:
Dissimilation, or, I feel this algorithm make the more complex the , B into B=2 ^ 5 + 2 2 ^ ^ 3 + 1 + 2 ^ 0, A need into this form? Didn't quite understand the idea of the algorithmCodePudding user response:
Is not exclusive or, chengfang,X ^ ^ (a + b)=X * X ^ b