Cod sursa(job #3302567)

Utilizator RosheRadutu Robert Roshe Data 8 iulie 2025 22:17:16
Problema Ciurul lui Eratosthenes Scor 0
Compilator py Status done
Runda Arhiva educationala Marime 0.59 kb
from bitarray import bitarray

class Solution:
    def __init__(self, N):
        self.N = N
        self.v = bitarray(N+1) 
        self.v.setall(True)
        self.v[0] = self.v[1] = 0
        self.__counter = 0

    def eratosthenes(self):
        for x in range(2, int(self.N**0.5)+1):
           if self.v[x]:
                self.v[x*x:self.N+1:x] = False
        self.__counter = self.v.count(True) 
    @property
    def counter(self):
        return self.__counter
    

with open("ciur.in", "r") as f:
    number = int(f.readline())
    s = Solution(number)
    s.eratosthenes()
    print(s.counter)