mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-01 18:55:23 +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
22 lines
500 B
Ruby
22 lines
500 B
Ruby
=begin
|
|
File: fast_power.rb
|
|
Created Time: 2026-08-18
|
|
Author: Hello Algo Team
|
|
=end
|
|
|
|
### 빠른 거듭제곱 ###
|
|
def fast_pow(x, n)
|
|
return 1 if n == 0
|
|
|
|
half = fast_pow(x, n / 2)
|
|
return half * half if n.even?
|
|
|
|
half * half * x
|
|
end
|
|
|
|
if __FILE__ == $0
|
|
raise '빠른 거듭제곱 검증에 실패했다' unless fast_pow(7, 0) == 1
|
|
raise '빠른 거듭제곱 검증에 실패했다' unless fast_pow(3, 5) == 243
|
|
raise '빠른 거듭제곱 검증에 실패했다' unless fast_pow(2, 6) == 64
|
|
end
|