I'm trying to compute this:
x^y (mod a)
Using recursion as it works better for larger numbers. Here's what I have:
public int mod (int x, int y, int a){
if(y == 2){
return x^2%a;
}
if(y%2 == 1){
return a%m*mod(x , y/2, a);
}
if(y%2 == 0 ){
return mod(x, y/2, a);
}
}
The code doesnt work and another issue is the "missing return statement" error at the last bracket. What can be done to fix this?