Wolverine Trading Interview Question: Write an algorithm to find al... | Glassdoor

Interview Question

Software Engineer Interview(Student Candidate) Chicago, IL

Write an algorithm to find all the prime numbers from 1 to n

Answer

Interview Answer

1 Answer

1

Just out of curiosity. I haven't done this for long time and no longer in IT. So this is out of blue. I'll try divide by 2, and cap at n/2, then by 3, cap at n/3, then 5, 7, etc, skip any number is a multiple of 2, 3, 5, 7, etc. until the denominator goes bigger than the cap. Make sense?

Nait on Apr 19, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.