/// لا إله إلا الله وحده لا شريك له، له الملك وله الحمد وهو على كل
///شيء قدير، الحمد الله وسبحان الله ولا إله إلا الله والله أكبر ولا حول ولا قوة إلا بالله
///اللَّهُمَّ رَبَّنَا آتِنَا فِي الدُّنْيَا حَسَنَةً وَفِي الْآخِرَةِ حَسَنَةً وَقِنَا عَذَابَ النَّارِ
#include <bits/stdc++.h>
#define debug(x) clog<< "["#x" = "<<(x)<<"]\n "
#define logic(x) cout<<(x?"YES":"NO")<<"\n"
using ll =long long ;
using namespace std;
const int N=1e5+10;
vector<int> grundy_number(N),mex(N),grundyNumberPrefixSum(N);
vector< pair<int,int> > operation [N];
signed main()
{
/// do not type any thing before you make sure your idea is totally true
ios::sync_with_stdio(0), cin.tie(0),cout.tie(0),clog.tie(0);
int n;
cin>>n;
for(int i=1; i<=n; i++)
{
ll sum=0,cnt=0;
for(int j=i; ; j++)
{
sum+=j;
cnt++;
if(sum>n)break;
if(cnt>1)
operation[sum].push_back({cnt,i});
}
}
for(int j=3; j<=n; j++)
{
for(auto it :operation[j])
{
mex[grundyNumberPrefixSum[it.second+it.first-1]^grundyNumberPrefixSum[it.second-1]]=1;
}
int m=0;
while(mex[m])m++;
grundy_number[j]=m;
for(auto it :operation[j])
{
mex[grundyNumberPrefixSum[it.second+it.first-1]^grundyNumberPrefixSum[it.second-1]]=0;
}
grundyNumberPrefixSum[j]=grundyNumberPrefixSum[j-1]^grundy_number[j];
}
if(grundy_number[n]==0)
{
cout<<"-1\n";
return 0;
}
ll mn=1e18;
for(auto it:operation[n])
{
if(!(grundyNumberPrefixSum[it.second+it.first-1]^grundyNumberPrefixSum[it.second-1]))
{
mn=min(mn,1ll*it.first);
}
}
cout<<mn<<"\n";
}
1395A - Boboniu Likes to Color Balls | 1637C - Andrew and Stones |
1334B - Middle Class | 260C - Balls and Boxes |
1554A - Cherry | 11B - Jumping Jack |
716A - Crazy Computer | 644A - Parliament of Berland |
1657C - Bracket Sequence Deletion | 1657B - XY Sequence |
1009A - Game Shopping | 1657A - Integer Moves |
230B - T-primes | 630A - Again Twenty Five |
1234D - Distinct Characters Queries | 1183A - Nearest Interesting Number |
1009E - Intercity Travelling | 1637B - MEX and Array |
224A - Parallelepiped | 964A - Splits |
1615A - Closing The Gap | 4C - Registration System |
1321A - Contest for Robots | 1451A - Subtract or Divide |
1B - Spreadsheet | 1177A - Digits Sequence (Easy Edition) |
1579A - Casimir's String Solitaire | 287B - Pipeline |
510A - Fox And Snake | 1520B - Ordinary Numbers |