Is 2021 A Prime Number?
A prime number is a positive integer that can only be exactly divided by itself and 1.
Algorithm: to judge whether X is a prime number or not, we can assume a number n has n x n = X (n = sqrt(X)). If X is not prime, it will have at least one integer pair n1 and n2, such that n1 x n2 = X, n1∈[2,n], n2∈[n,X]. We can then narrow down the scope that if X is exactly divisible by a number between 2 and sqrt(X), it is not a prime; otherwise, it is a prime.
Posted by Sha Cheng on Wednesday, December 23, 2020