Series Sum I


Problem Statement

You are given two integers nn and kk.

You have the following infinite sequence S=[1 mod k,   (1+2) mod k,   (1+2+3) mod k, ...]S = [1 \small\text{ mod } \normalsize k,\ \ \ (1 + 2) \small\text{ mod }\normalsize k,\ \ \ (1 + 2 + 3) \small\text{ mod }\normalsize k,\ ... ], in other words Si=(j=1ij) mod kS_i = (\sum_{j=1}^ij) \small\text{ mod }\normalsize k.

Determine the value of SnS_n, in other words, determine the nthn^{th} value of the infinite sequence.

Input Format

Your first line will contain three space-separated integers nn and kk respectively.

Output Format

You should output a single integer SnS_n, the nthn^{th} integer of SS (one-indexed).

Constraints

  • 1n1091 \leq n \leq 10^{9}
  • 1k1091 \leq k \leq 10^9

Sample Cases

Input 1
1 10
Output 1
1
Input 2
3 10
Output 2
6
Input 3
4 10
Output 3
0
Input 4
123451234 123451234
Output 4
61725617

Template

Code 1
n, k = map(int, input().split())

# print your output

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.