Count primes below n · ספירת מספרים ראשוניים מתחת ל-n
Count primes below n
Return how many prime numbers are strictly less than n. A prime has no divisors other than 1 and itself. For each candidate k, test divisors only up to √k (i.e. while d * d <= k) — once one divides k evenly, it isn't prime.
ספור מספרים ראשוניים מתחת ל-n
החזר כמה מספרים ראשוניים הם קטנים מ n בהכרח. מספר ראשוני אין לו מחלקים אלא 1 ועצמו. עבור כל מועמד k, בדוק מחלקים רק עד √k (כלומר: בזמן ש-d * d <= k) — ברגע שמישהו מחלק את k במלואו, הוא אינו ראשוני.
Complete countPrimes(int n) returning how many prime numbers are strictly less than n. Example: countPrimes(10) is 4 (2, 3, 5, 7). · השלם את countPrimes(int n) החוזר כמה מספרים ראשוניים קיימים שגדלים מn באופן מוחלט. דוגמה: countPrimes(10) היא 4 (2, 3, 5, 7).
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.