adapt to update sieves for additive functions
This commit is contained in:
@@ -16,21 +16,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package sieve
|
||||
|
||||
func primeOmegaUpdateMultiples(sieve []uint, p uint, n uint) {
|
||||
for q := p; ; q *= p {
|
||||
// omega(a*b) = omega(a) + omega(b) if gcd(a,b) = 1
|
||||
for i := 2 * q; i < n; i += q {
|
||||
if i%(p*q) != 0 {
|
||||
sieve[i] += sieve[q]
|
||||
}
|
||||
}
|
||||
|
||||
if p*q >= n {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updatePowers(sieve []uint, p uint, n uint) {
|
||||
for q := p; p*q < n; q *= p {
|
||||
sieve[p*q] = 1 + sieve[q]
|
||||
@@ -60,7 +45,7 @@ func PrimeOmega(n uint, multiplicity bool, buflen uint) chan uint {
|
||||
updatePowers(sieve, i, n)
|
||||
}
|
||||
|
||||
primeOmegaUpdateMultiples(sieve, i, n)
|
||||
updateMultiples(sieve, i, n, true)
|
||||
ch <- sieve[i]
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user