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
- 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
- Queries for the smallest and the largest prime number of given digit
- 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
- Sum and product of k smallest and k largest prime numbers in the array
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Find coordinates of a prime number in a Prime Spiral
- Check if a prime number can be expressed as sum of two Prime Numbers
- Smallest number dividing minimum number of elements in the array | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.