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 to return the absolute difference between L-th smallest number and the R-th smallest number
- Greatest divisor which divides all natural number in range [L, R]
- Largest Divisor of a Number not divisible by a perfect square
- Next smallest prime palindrome
- Sum and product of k smallest and k largest prime numbers in the array
- Check if a prime number can be expressed as sum of two Prime Numbers
- Find coordinates of a prime number in a Prime Spiral
- Number which has the maximum number of distinct prime factors in the range M to N
- Find the smallest number whose digits multiply to a given number n
- Super Ugly Number (Number whose prime factors are in given set)
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.