FactSet Interview Question

How work you work out all the prime numbers up to a given range?

Interview Answers

Anonymous

Apr 22, 2012

Sieve of Eratosthenes algorithm. create an array of the numbers, set them all to the value 1. Start at 2, set every second number after 2 to 0. move to the next number (3). change every third number after three to zero. stop when there's no more numbers set to 1 or you reach the end of the array. At the end, the numbers marked 1 are the primes.

4

Anonymous

Aug 28, 2012

Interview candidate - did you give that answer in the interview? If so, what did they say?

Anonymous

Apr 20, 2012

Store all the prime numbers in an array and compare the next number with the array to find out whether it is prime or not.