Given two positive integers L and R, the task is to count the elements from the range [L, R] whose prime factors are only 2 and 3.
Input: L = 1, R = 10
2 = 2
3 = 3
4 = 2 * 2
6 = 2 * 3
8 = 2 * 2 * 2
9 = 3 * 3
Input: L = 100, R = 200
Approach: Start a loop from L to R and for every element num:
- While num is divisible by 2, divide it by 2.
- While num is divisible by 3, divide it by 3.
- If num = 1 then increment the count as num has only 2 and 3 as its prime factors.
Print the count in the end.
Below is the implementation of the above approach:
- Count numbers in a range having GCD of powers of prime factors equal to 1
- K-Primes (Numbers with k prime factors) in a range
- Count common prime factors of two numbers
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Sum of numbers in a range [L, R] whose count of divisors is prime
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Queries for the difference between the count of composite and prime numbers in a given range
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime
- Common prime factors of two numbers
- Sum of all even factors of numbers in the range [l, r]
- Sum of all odd factors of numbers in the range [l, r]
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Number of distinct prime factors of first n natural numbers
- Sort an array according to the increasing count of distinct Prime Factors
- Number which has the maximum number of distinct prime factors in the range M to N
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.