How to Determine a Prime Number Efficiently

Using the trial division algorithm

Mahbub Zaman
Logic Gates

--

Photo by Format from Pexels

A prime number is a positive integer exactly divisible by 1 and itself. In other words, a prime number will have only 2 factors. The first ten prime numbers are.

2, 3, 5, 7, 11, 13, 17, 19, 23

1 is not a prime number because it’s not divisible by exactly 2 positive integers. This article will discuss how to determine a prime number and make it better in terms of time complexity using four different methods.

RSA (Rivest–Shamir–Adleman) algorithm is based on the fact that finding the prime factorization of a large number is hard. When we can express a number into only prime factors, it’s called prime factorization. Modern Encryption is one of the significant reasons that we care so much about prime numbers.

Before we start, I’ll talk briefly about the efficiency of algorithms. An efficient algorithm always takes the minimum CPU (central processing unit) time and memory. We use O-notation (order notation) to represent computing time for algorithms in terms of size n. For example, an O(1) algorithm will take constant time, an O(n) algorithm will take linear time, an O(n²) algorithm will take quadratic time to solve a problem. So when we write an algorithm, we always try to maximize performance by optimizing Order…

--

--

Mahbub Zaman
Logic Gates

I create open-source developer productivity tools, intending to streamline and enhance workflow: binarytree.dev