#K38652. Sum of Triangle Numbers Modulo
Sum of Triangle Numbers Modulo
Sum of Triangle Numbers Modulo
In this problem, you are given two integers (n) and (m). Your task is to calculate the sum of the first (n) triangle numbers, and then output the result modulo (m).
A triangle number (T(i)) is defined as (T(i) = \frac{i(i+1)}{2}). Therefore, you need to compute:
[
S = \left(\sum_{i=1}^{n} \frac{i(i+1)}{2}\right) \bmod m
]
Make sure that you use modulo operations appropriately to avoid overflow during computations.
inputFormat
The input consists of a single line containing two integers (n) and (m) (separated by a space), where (n) is the number of triangle numbers to sum and (m) is the modulus.
outputFormat
Output a single integer, which is the sum of the first (n) triangle numbers modulo (m).## sample
4 100
20