Series Sum II
Problem Statement
You are given three integers n, x 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 at which index (one-indexed) the nth occurrence of x is in the sequence S if x occurs at least n times, otherwise output −1.
Input Format
Your first line will contain three space-separated integers n, x and k respectively.
Output Format
You should output a single integer, representing the index (one-indexed) in S at which the nth occurrence of x appears. If it does not appear at least n times, then output −1.
Constraints
- 1≤n≤109
- 1≤k≤102
- 0≤x<k
Sample Cases
1 1 10
1
2 1 10
6
20 2 13
124
20 2 10
-1
Template
n, x, 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.