java binary exponentiation
/**
* Calculate a^n in O(logn) time, instead of O(n) time with naive approach.
**/
public static long powerRecursive(int base, int exponent){
if(exponent == 0) return 1;
return (exponent % 2 == 0) ?
powerRecursive(base, exponent / 2) * powerRecursive(base, exponent / 2)
: base * powerRecursive(base, (exponent - 1) / 2) *
powerRecursive(base, (exponent - 1) / 2);
}
Also in Java:
- android dismiss keyboard
- java shuffle list
- para que sirve getcontentpane en java
- system.arraycopy java
- android studio java random number generator
- java stack methods
- ndroid.support.v4.content.FileProvider
- java create directory
- difference between compile and execute in java
- java loop through object
- how to do 4th root java
- java find duplicates in array
- e
- java binary exponentiation
- string to long java
- main method java
- processing sound android
- blurview android github
- bubble sort in java
- creating file in specific location in java application
- sending a excel in an attachment in email java
- how to open a webpage with java
- java file class
- prendere valore da tastiera java