# frozen_string_literal: true l, r, m = gets.chomp.split.map(&:to_i) l %= m r %= m if l < r p(r - l + 1) elsif l == r p(1) else p(m - (l - r - 1)) end