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
- Number of n digit numbers that do not contain 9
- Smallest number divisible by first n numbers
- Largest number in [2, 3, .. n] which is co-prime with numbers in [2, 3, .. m]
- Average of even numbers till a given even number
- Express a number as sum of consecutive numbers
- Sum of n digit numbers divisible by a given number
- Number of occurrences of 2 as a digit in numbers from 0 to n
- Number of perfect squares between two given numbers
- Number of n digit stepping numbers
- Average of odd numbers till a given odd number
- Minimum number of sets with numbers less than Y
- Find if given number is sum of first n natural numbers
- Number of digits in the product of two numbers
- Express an odd number as sum of 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 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