You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
225 B
Go
17 lines
225 B
Go
4 years ago
|
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
|
||
|
}
|