Given a number N, find the smallest prime divisor of N.
- Check if the number is divisible by 2 or not.
- Iterate from i = 3 to sqrt(N) and making a jump of 2.
- If any of the numbers divide N then it is the smallest prime divisor.
- If none of them divide, then N is the answer.
Below is the implementation of the above algorithm:
How to efficiently find prime factors of all numbers till n?
Please refer Least prime factor of numbers till n
- Find the k-th smallest divisor of a natural number N
- Smallest divisor D of N such that gcd(D, M) is greater than 1
- Smallest prime number missing in an array
- Queries for the smallest and the largest prime number of given digit
- Check if the first and last digit of the smallest number forms a prime
- Smallest Special Prime which is greater than or equal to a given number
- Largest Divisor for each element in an array other than 1 and the number itself
- Queries to return the absolute difference between L-th smallest number and the R-th smallest number
- Largest Divisor of a Number not divisible by a perfect square
- Greatest divisor which divides all natural number in range [L, R]
- Next smallest prime palindrome
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Sum and product of k smallest and k largest prime numbers in the array
- Find coordinates of a prime number in a Prime Spiral
- Check if a prime number can be expressed as sum of two Prime Numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.