mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-02 03:05:24 +08:00
* feat(ko): add the complete Korean online edition * Use UTF-8 for Python CI output on Windows * Remove print-book promotion from the Korean site * fix(ko): preserve emphasis before Korean particles
28 lines
581 B
Java
28 lines
581 B
Java
/**
|
|
* File: fast_power.java
|
|
* Created Time: 2026-08-18
|
|
* Author: Hello Algo Team
|
|
*/
|
|
|
|
package chapter_divide_and_conquer;
|
|
|
|
public class fast_power {
|
|
/* 빠른 거듭제곱 */
|
|
static int fastPow(int x, int n) {
|
|
if (n == 0) {
|
|
return 1;
|
|
}
|
|
int half = fastPow(x, n / 2);
|
|
if (n % 2 == 0) {
|
|
return half * half;
|
|
}
|
|
return half * half * x;
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
assert fastPow(7, 0) == 1;
|
|
assert fastPow(3, 5) == 243;
|
|
assert fastPow(2, 6) == 64;
|
|
}
|
|
}
|