MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Factorize

Function Factorize

math/prime/primefactorization.go:10–27  ·  view source on GitHub ↗

Factorize is a function that computes the exponents of each prime in the prime factorization of n

(n int64)

Source from the content-addressed store, hash-verified

8// Factorize is a function that computes the exponents
9// of each prime in the prime factorization of n
10func Factorize(n int64) map[int64]int64 {
11 result := make(map[int64]int64)
12
13 for i := int64(2); i*i <= n; i += 1 {
14 for {
15 if n%i != 0 {
16 break
17 }
18 result[i] += 1
19 n /= i
20 }
21
22 }
23 if n > 1 {
24 result[n] += 1
25 }
26 return result
27}

Callers 3

LiouvilleLambdaFunction · 0.92
TestFactorizeFunction · 0.85
BenchmarkFactorizeFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestFactorizeFunction · 0.68
BenchmarkFactorizeFunction · 0.68