During QA validation of large totals in the Coupa Supplier Portal, you need to compute the sum of every integer from 1 through N - 1. Because N may contain hundreds of thousands of digits, you must not iterate through the range or convert the entire value to a native integer.
Return the result modulo mod.
Implement sum_before_mod(n, mod), where:
n is a decimal string representing an integer N >= 1.mod is a positive integer.(1 + 2 + ... + (N - 1)) % mod.Use the identity N * (N - 1) / 2, but divide one factor by 2 before applying the modulo so the method works even when mod is even.
def sum_before_mod(n, mod):