Series Sum I
Problem Statement
You are given two integers n and k.
You have the following infinite sequence S=[1 mod k, (1+2) mod k, (1+2+3) mod k, ...], in other words Si=(∑j=1ij) mod k.
Determine the value of Sn, in other words, determine the nth value of the infinite sequence.
Input Format
Your first line will contain three space-separated integers n and k respectively.
Output Format
You should output a single integer Sn, the nth integer of S (one-indexed).
Constraints
- 1≤n≤109
- 1≤k≤109
Sample Cases
1 10
1
3 10
6
4 10
0
123451234 123451234
61725617
Template
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.