Files
hello-algo/ko/codes/java/chapter_divide_and_conquer/fast_power.java
T
Yudong Jin 2f561d3d51 feat(ko): add the Korean online edition (#2006)
* 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
2026-10-29 03:46:43 +08:00

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;
}
}