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.
- Represent a number as a sum of maximum possible number of Prime Numbers
- Sum of two numbers if the original ratio and new ratio obtained by adding a given number to each number is given
- Number of n digit numbers that do not contain 9
- Kth number from the set of multiples of numbers A, B and C
- Number of occurrences of 2 as a digit in numbers from 0 to n
- Numbers that are not divisible by any number in the range [2, 10]
- Number of n digit stepping numbers
- Largest number in [2, 3, .. n] which is co-prime with numbers in [2, 3, .. m]
- Express a number as sum of consecutive numbers
- Express an odd number as sum of prime numbers
- Sum of n digit numbers divisible by a given number
- Average of odd numbers till a given odd number
- Represent the given number as the sum of two composite numbers
- Number of perfect squares between two given numbers
- Find if given number is sum of first n natural 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 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.
Improved By : jit_t