Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ExponentiationBySquaring
- {
- static int power(int x,int n){
- if(n==1)return x;
- if((n & 1)==0) return power(x*x,n/2);
- return x*power(x*x,(n-1)/2);
- }
- public static void main (String[] args) throws java.lang.Exception
- {
- System.out.println(power(2,11));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement