atcoder#ACL1B. Sum is Multiple

Sum is Multiple

Score : 600600 points

Problem Statement

Given is an integer NN. Find the minimum possible positive integer kk such that (1+2++k)(1+2+\cdots+k) is a multiple of NN. It can be proved that such a positive integer kk always exists.

Constraints

  • 1N10151 \leq N \leq 10^{15}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

Output

Print the answer in a line.

11
10

1+2++10=551+2+\cdots+10=55 holds and 5555 is indeed a multple of N=11N=11. There are no positive integers k9k \leq 9 that satisfy the condition, so the answer is k=10k = 10.

20200920
1100144