A P-smooth number or P-friable number is an integer whose largest prime factor is less than or equal to P. Given N and P, we need to write a program to check whether it is P-friable or not.
Input : N = 24 , P = 7 Output : YES Explanation : The prime divisors of 24 are 2 and 3 only. Hence its largest prime factor is 3 which is less than or equal to 7, it is P-friable. Input : N = 22 , P = 5 Output : NO Explanation : The prime divisors are 11 and 2, hence 11>5, so it is not a P-friable number.
The approach will be to prime factorize the number and store the maximum of all the prime factors. We first divide the number by 2 if it is divisible, then we iterate from 3 to Sqrt(n) to get the number of times a prime number divides a particular number which reduces every time by n/i and store the prime factor i if its divides N. We divide our number n (by prime factors) by its corresponding smallest prime factor till n becomes 1. And if at the end n > 2, it means its a prime number, so we store that as a prime factor as well. At the end the largest factor is compared with p to check if it is p-smooth number or not.
- Stormer Numbers
- k-Rough Number or k-Jagged Number
- Frugal Number
- Lemoine's Conjecture
- P - smooth numbers in given ranges
- Check whether a number is semiprime or not
- Find largest prime factor of a number
- Prime Numbers
- Exponential Squaring (Fast Modulo Multiplication)
- Count Primes in Ranges
- Tiling Problem
- Euclidean algorithms (Basic and Extended)
- Segment Tree | Set 1 (Sum of given range)
- Sieve of Eratosthenes
- Program for Fibonacci 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.
Improved By : jit_t