Sieve Of Eratosthenes

    0

    0

    Naman-Singla777

    sieveprime
    Primes

    Let's you find all prime numbers upto a certain number (which it takes as an argument)

    def SieveOfEratosthenes(n):
        # j = n
        # n = 15*n
        nums = {}
        for i in range(2, n+1):
            nums[i] = 1
        for i in nums:
            if nums[i] == 1:
                k = 2
                m = k*i
                while m <= n:
                    k+=1
                    nums[m] = 0
                    m = k*i
        ans = []
        for k in nums:
            if nums[k] == 1:
                ans.append(k)
        return ans
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.