Finding Prime Numbers Up to N: A Scientific Approach

In summary, a prime number is a positive integer with exactly two factors - 1 and itself. To find prime numbers up to a given number, N, the "Sieve of Eratosthenes" algorithm can be used. The largest known prime number as of June 2021 is 2^82,589,933 - 1, with over 24 million digits. While there are some patterns and rules for identifying prime numbers, there is no known formula or algorithm to generate all prime numbers. Prime numbers are important in cryptography, as well as in fields such as number theory, computer science, and physics. They also serve as fundamental building blocks in the study of mathematics.
  • #1
TimNguyen
80
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
  • #2
Don't sound like a [strictly-] MATLAB question... but more like a homework problem.

How would you do it by hand with (say) N=60?
 
  • #3
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.
 

1. What is the definition of a prime number?

A prime number is a positive integer that is only divisible by 1 and itself. In other words, it has exactly two factors.

2. How do you find prime numbers up to a given number, N?

One method is to use the "Sieve of Eratosthenes" algorithm, which involves systematically eliminating all the multiples of each prime number starting from 2 up to the given number, N. The remaining numbers after this process are the prime numbers up to N.

3. What is the largest known prime number?

As of June 2021, the largest known prime number is 2^82,589,933 – 1, which has over 24 million digits. It was discovered in December 2018.

4. Are there any patterns or rules for finding prime numbers?

While there are some patterns and rules that can help identify prime numbers, such as the fact that all prime numbers greater than 3 are of the form 6n ± 1, there is no known formula or algorithm that can generate all prime numbers.

5. Why are prime numbers important in mathematics and science?

Prime numbers play a crucial role in cryptography, as they are used in creating secure encryption methods. They also have applications in various fields such as number theory, computer science, and physics. Additionally, prime numbers are fundamental building blocks in the study of mathematics and help us better understand the properties of numbers.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
17
Views
448
Replies
5
Views
398
  • Programming and Computer Science
Replies
22
Views
730
Replies
8
Views
355
  • Precalculus Mathematics Homework Help
Replies
9
Views
1K
Replies
5
Views
1K
  • Precalculus Mathematics Homework Help
Replies
3
Views
934
  • Calculus and Beyond Homework Help
Replies
22
Views
2K
Replies
1
Views
750
Replies
1
Views
1K
Back
Top