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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Number of ways to obtain each numbers in range [1, b+c] by adding any two numbers in range [a, b] and [b, c]
- 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
- Count numbers which can be constructed using two numbers
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Permutation of numbers such that sum of two consecutive numbers is a perfect square
- Numbers within a range that can be expressed as power of two numbers
- Numbers less than N which are product of exactly two distinct prime numbers
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Count numbers which are divisible by all the numbers from 2 to 10
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- Check if a given pair of Numbers are Betrothed numbers or not
- Count of numbers upto M divisible by given Prime Numbers
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Maximize count of equal numbers in Array of numbers upto N by replacing pairs with their sum
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Number of factors of very large number N modulo M where M is any prime number
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