L, R, M = map(int, input().split()) if M == 1: print(0) exit() # Compute K and s_prev s_prev = [] current_fact = 1 # Represents (i-1)! % M initially, but modified in loop prod = 1 K = None # We need to compute up to K where prod becomes zero for i in range(1, M + 1): current_fact = (current_fact * i) % M prod = (prod * current_fact) % M if prod == 0: K = i break s_prev.append(prod) else: # In case M is a very large prime and K=M. But since we loop up to M steps, theoretically, K must be <= M. K = M + 1 # Not possible, but to handle edge cases s_prev = [] # Build prefix sum array prefix_sum = [0] current_sum = 0 for x in s_prev: current_sum = (current_sum + x) % M prefix_sum.append(current_sum) start = max(L, 1) end = min(R, K - 1) if start > end: total = 0 else: if end >= len(prefix_sum): end = len(prefix_sum) - 1 total = (prefix_sum[end] - prefix_sum[start - 1]) % M print(total % M)