#include <iostream>
using namespace std;
int main()
{
int k, g, s, x, poz;
cin >> k;
if (k<3) cout << k;
else
{
x=1;
while (x*(x+1)<k) ++x;
g=x-1;
s=g*(g+1);
poz=k-s;
if (poz==0) cout << 2;
else
{
if (poz<=x+1) cout << poz;
else { poz=poz-(x+1); cout << (x+1)-poz; }
}
}
return 0;
}
-------------------------------------------------------------
varianta 2 cu depasiri ........................
#include <iostream>
using namespace std;
long long i, j, k, crestere, t;
int main()
{
cin >> k;
t=1; j=1;
while (i<k)
{
if (j==1) { crestere=1; ++t; }
if (j==t) { crestere=-1; }
cout << j << " ";
++i;
if (i<k) j+=crestere;
}
cout << "\n";
cout << j;
}