move to lib

This commit is contained in:
filifa
2025-09-29 21:52:52 -04:00
parent d2275cd69f
commit b55fe61820
16 changed files with 452 additions and 296 deletions

View File

@@ -21,27 +21,9 @@ import (
"math/big"
"github.com/spf13/cobra"
"scm.dairydemon.net/filifa/mathtools/internal/lib"
)
// TODO: expand to work for different sigmas
func divisorSummatory(n *big.Int) *big.Int {
// employing Dirichlet's hyperbola method
sqrt := new(big.Int).Sqrt(n)
total := big.NewInt(0)
for x := big.NewInt(1); x.Cmp(sqrt) <= 0; x.Add(x, big.NewInt(1)) {
z := new(big.Int).Div(n, x)
total.Add(total, z)
}
total.Mul(total, big.NewInt(2))
sqrt.Exp(sqrt, big.NewInt(2), nil)
total.Sub(total, sqrt)
return total
}
func divisorSum(cmd *cobra.Command, args []string) {
for _, arg := range args {
n, ok := new(big.Int).SetString(arg, 10)
@@ -50,7 +32,7 @@ func divisorSum(cmd *cobra.Command, args []string) {
continue
}
d := divisorSummatory(n)
d := lib.DivisorSummatory(n)
fmt.Println(d)
}
}