Sum is Multiple

AtCoder
IDacl1_b
Time2000ms
Memory256MB
Difficulty
Given is an integer $N$. Find the minimum possible positive integer $k$ such that $(1+2+\cdots+k)$ is a multiple of $N$. It can be proved that such a positive integer $k$ always exists. ## Constraints * $1 \leq N \leq 10^{15}$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ [samples]
Samples
Input #1
11
Output #1
10

$1+2+\cdots+10=55$ holds and $55$ is indeed a multple of $N=11$. There are no positive integers $k \leq 9$ that satisfy the condition, so the answer is $k = 10$.
Input #2
20200920
Output #2
1100144
API Response (JSON)
{
  "problem": {
    "name": "Sum is Multiple",
    "description": {
      "content": "Given is an integer $N$. Find the minimum possible positive integer $k$ such that $(1+2+\\cdots+k)$ is a multiple of $N$. It can be proved that such a positive integer $k$ always exists.",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "acl1_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given is an integer $N$. Find the minimum possible positive integer $k$ such that $(1+2+\\cdots+k)$ is a multiple of $N$. It can be proved that such a positive integer $k$ always exists.\n\n## Constraint...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments