Merge pull request #31 from ridwanfathin/master

add fast pow: O(log n) exponent
pull/35/head
0xAX 4 years ago committed by GitHub
commit e1dcce7b01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,16 @@
package numerical
//O(log n) function for pow(x, y)
func FastPow(n uint, power uint) uint {
var res uint = 1
for power > 0 {
if (power & 1) != 0 {
res = res * n
}
power = power >> 1
n = n * n
}
return res
}
Loading…
Cancel
Save