import sympy,math g=lambda L,N,m:math.prod((pow(e+1,N,m)-2*pow(e,N,m)+pow(e-1,N,m))%m for p,e in sympy.factorint(L).items()) f=lambda G,L,N,m:sum((b-G+1)*g(k,N,m)%m for k in range(1,L//G+1) if (b:=L//k)>=G)%m print(f(10**6,10**12,10**18,101**4))