@akash19jain is absolutely right. @shyam339 please provide a link to the problem and your code in the future. This will help others in assisting you.
The code of the problem is HMAPPY2 and here is a link to it.
Subtask 2: (TLE)
Notice that for this subtask, K and N can be as high as 10^{18}. So if you run a loop from 1 to N, and thus  from 1 to 10^{18}, you will get TLE. Instead, you need to find a way such that it counts, without any loops, all numbers from 1 to N,
 Which are divisible by A (x)
 Divisible by B (y)
 Divisible by both A and B (z)
Then the count will be x+y2z;

x is nothing but N/A

y is nothing but N/B
 Now we need to find out z, which is, number of numbers from 1 to N divisible by both A and B. To find z, we need to find the LCM of A and B. We can find the LCM if we find out the GCD of A and B (Remember LCM = (A*B)/GCD). You can read about finding the GCD here. Once we have the LCM, then z = N/LCM.
Here is my AC code for this problem. Feel free to ask if you have any more doubts.