adapt to update sieves for additive functions

This commit is contained in:
filifa
2025-10-07 18:10:44 -04:00
parent df317e0837
commit c842762ca9
4 changed files with 9 additions and 20 deletions

View File

@@ -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]
}
}()