The exact formula is explained on P1 of this thread :/
You will gain skill so long as your skill is within 30 skill points of the rLVL / iLVL of the item.