This question already has an answer here:
How many functions f:N→N satisfy - $$lcm(f(n), n) - hcf(f(n), n)<5?$$
At first I tried to use the property that
→ LCM*HCF=Product of the two numbers
Hence I got $$lcm.hcf=n.f(n)$$
And the other given relation in the question.
But, after this I was not able to proceed further.