CodeChef - Please like me
I think the key thing you are missing isn't a better pow function.  The problem is that you are iterating d times without checking whether you have surpassed l.  Notice that for the lowest c of 1, you are multiplying by 2 every loop.  The maximum l is 1000000000 which is less than 2^30.  Therefore the max number of loops you will ever need is 30.

If you simply checked every loop:

if (x &gt;= l)
    break;


then you limit your loop to 30 iterations instead of 1000000000 iterations.