Finding Prime Numbers Up to N: A Scientific Approach

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 3K views
TimNguyen
Messages
79
Reaction score
0
How would I write a program that finds all the prime numbers that are less than or equal to a "user-supplied" integer N, implementing the fact that I should only be dividing N by all prime numbers less than sqrt(N)?
 
Physics news on Phys.org
there should be a function that checks whether a resulting calculation is an integer or not (or you can always make your own function).

That's the key to this.