Divisors [0]
Divisors [0]
Let's consider the string of all natural numbers: 1,2,3,4,…
We'd like to find the sum of the first n values of this sequence, although that alone is a bit boring (how would we do this?)
Instead, we'd like to find the sum, only after doing a simple operation to the individual sequence values - taking their value modulo some m.
For example, for n=5, m=4, the sequence of the first 5 elements would be: 1,2,3,0,1, and the total sum would be 7.
Input
Input will contain two space-separated integers n and m, mirroring the definition from the statement
Output
Output a single integer representing the sum of the first n elements modulo m.
Constraints
- 1≤n≤109
- 1≤m≤109
Example
5 4
7
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.