commit
e1dcce7b01
@ -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…
Reference in New Issue