Skip to content

Instantly share code, notes, and snippets.

@toboqus
Created September 14, 2015 18:32
Show Gist options
  • Save toboqus/13b635b8dd1b33179218 to your computer and use it in GitHub Desktop.
Save toboqus/13b635b8dd1b33179218 to your computer and use it in GitHub Desktop.
Russian peasant algorithm
public class RussianPeasant {
public Static int product(int a, int b){
int x = a;
int y = b;
int z = 0;
while(x > 0){
if(x%2 == 1) z += y;
x = x >> 1;
y = y << 1;
}
return z;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment