l,r,m = map(int, input().split()) z = 1 k = 1 for i in range(1, l + 1): z *= i k *= z if k % m == 0: print(0) exit() f = k if f % m == 0: print(0) exit() count = 0 prev = -1 for i in range(l + 1, r + 1): z *= i k *= z f += k r = f%m if prev == r: count += 1 else: count = 0 if count > 100: print(r) exit() prev = r print(f%m)