I thought of solving it using segmented sieve. Like first I’ll calculate the prime factorisation of each number from l to r , then for each i’ll just multiply their powers of prime factor to get the total no. of factors of that number.

if total factors==3 then i’ll increament the ans else continue with the rest.

Can this approach be accepted? Or is there any better approach to solve it?