Problem:
Score : 600 points

Problem Statement

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

Output

Print the answer in a line.

Sample Input 1

11

Sample 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.

Sample Input 2

20200920

Sample Output 2

1100144

Solution in C++ (GCC 9.2.1) (judge verdict: Time Limit Exceeded)

  
#include <bits/stdc++.h>
#include<vector>
#include<set>
#define ll long long
using namespace std;
bool isprime(int k)
{
	for(int i=2;i*i<=k;i++)
	{
		if(k%i==0)return false;
	}
	return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll t,a,b,c,d=0,n,m,k=0,sum=0,i,j;
   
   bool cheak=true,ok=true;
     vector<ll>v;
     
      ll mx=0;
      cin>>n;
       for(i=1;i<=n;i++)
       {
       	 d=(i*(i+1)/2);
       	 if(d%n==0)
			{
				cout<<i<<endl;
				break;
			}
	   }
       
      
      
  return 0;
}