fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let l: usize = itr.next().unwrap().parse().unwrap(); let r: usize = itr.next().unwrap().parse().unwrap(); let m: usize = itr.next().unwrap().parse().unwrap(); let fact = |x| { let mut y = 1; for i in 1..=x { y *= i; } y }; let mut ans: usize = 0; for i in l..=r { let mut x = 1; for j in 1..=i { if fact(j) % m == 0 { x = 0; break; } else { x = (x % m) * (fact(j) % m) } } ans = (ans + x) % m; if x % m == 0 { break; } } println!("{}", ans); }