O(1) approach of https://www.codechef.com/ACMIND17/problems/COMPEXP

Constraints of this question are very high. later i got to know we can obtain answer in O(1) by using some formulae =(2nk-2n+2)/k; but i did not get this . can anybody explain me this formulae ?

//