Want to know:
Use Sieve of Eratosthenes algorithm public int countPrimes(int n) { boolean[] isPrime = new boolean[n]; for(int i = 2; i < n; i++) { isPrime[i] = true; } for(int i = 2; i * i < n; i++) { if(!isPrime[i]) { continue; } else { for(int j= i * i; j < n; j += i) { isPrime[j] = false; } } } int counter = 0; for(int i = 2; i < n; i++) { if(isPrime[i]) { counter++; } } return counter; }
Get a detailed, AI-powered explanation for this question and thousands more on StudyFetch.
Get the Answer for FreeHow StudyFetch Helps You Master This Topic
AI-Powered Answers
Get instant, detailed explanations powered by AI that understands your course material.
Deep Understanding
Go beyond surface-level answers with step-by-step breakdowns and examples.
Personalized Learning
Sparky adapts to your learning style and helps you connect ideas.
Practice & Test
Turn any question into flashcards, quizzes, and practice tests to solidify your knowledge.
Explore More Questions
- A gym offers three levels of membership based on the number of visits per month, as represented by the table.Kaleigh wants to know how much she will pay for her gym membership. Which graph represents the total monthly cost at the gym as a function of the number of visits Kaleigh plans to make each month?
- La somme des probas est égale à
- Ursa Major Solar provides various levels of customer support. The VP of support wants an automated way to notify the support team when an unresolved Case has been open for over 4 hours. Which feature should be used to alert support managers when a case has been open for more than 4 hours?