move to lib
This commit is contained in:
@@ -20,39 +20,13 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib"
|
||||
)
|
||||
|
||||
var totientN uint
|
||||
|
||||
func totientSieve(n uint) chan uint {
|
||||
totients := make([]uint, n)
|
||||
totients[0] = 0
|
||||
totients[1] = 1
|
||||
for i := uint(2); i < n; i++ {
|
||||
totients[i] = i - 1
|
||||
}
|
||||
|
||||
ch := make(chan uint)
|
||||
go func() {
|
||||
for i := uint(0); i < n; i++ {
|
||||
ch <- totients[i]
|
||||
if i == 0 || i == 1 || totients[i] != i-1 {
|
||||
continue
|
||||
}
|
||||
|
||||
for j := uint(2 * i); j < n; j += i {
|
||||
totients[j] -= totients[j] / i
|
||||
}
|
||||
}
|
||||
|
||||
close(ch)
|
||||
}()
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
func totient(cmd *cobra.Command, args []string) {
|
||||
for v := range totientSieve(totientN) {
|
||||
for v := range lib.TotientSieve(totientN) {
|
||||
if v == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user