Skip to content
Discussion options

You must be logged in to vote

Thank you for this discussition solution is here Click For Solution

import math
from heapq import nlargest
from collections import defaultdict

MOD = 10**9 + 7

def count_prime_factors(n):
    """Returns the number of distinct prime factors of n."""
    factors = set()
    for i in range(2, int(math.sqrt(n)) + 1):
        while n % i == 0:
            factors.add(i)
            n //= i
    if n > 1:
        factors.add(n)
    return len(factors)

def precompute_prime_scores(limit=10**5):
    """Precomputes the prime scores for numbers from 1 to limit."""
    prime_scores = [0] * (limit + 1)
    
    for i in range(2, limit + 1):
        if prime_scores[i] == 0:  # `i` is a prime
            

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Antim-IWP
Comment options

Antim-IWP Mar 29, 2025
Collaborator Author

Answer selected by Antim-IWP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
help wanted Extra attention is needed question Further information is requested LeetCode
2 participants