Bit representation can do ? 1) to indicate whether there exist an element \/ a number \/ a valid operation here
Math.pow(x,y)
4 ^ 5 = 4 ^ 4 * 4
0 1 0 1
16*16*16*16 16*16 16 4
//assume x > 0, y > 0, no overflow.
public int pow(int x, int y) {
int runningProduct = 1;
int y = 1;
while (y != 0) {
if (x & 1 == 1) {
ret = ret * runningProduct;
}
runningProduct *= runningProduct;
y >> 1;
}
return ret;
}