Change project structure to a Maven Java project + Refactor (#2816)

This commit is contained in:
Aitor Fidalgo Sánchez
2021-11-12 07:59:36 +01:00
committed by GitHub
parent 8e533d2617
commit 9fb3364ccc
642 changed files with 26570 additions and 25488 deletions

View File

@ -0,0 +1,22 @@
package com.thealgorithms.divideandconquer;
public class BinaryExponentiation {
public static void main(String args[]) {
System.out.println(calculatePower(2, 30));
}
// Function to calculate x^y
// Time Complexity: O(logn)
public static long calculatePower(long x, long y) {
if (y == 0) {
return 1;
}
long val = calculatePower(x, y / 2);
val *= val;
if (y % 2 == 1) {
val *= x;
}
return val;
}
}