Solutia oficiala:
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("ksir.in");
ofstream fout("ksir.out");
unsigned long long k,g,p,s,d;
int main()
{
fin>>k;
//g=sqrt(k);
s=0;
d=k;
while(s+1<d)
{
g=(s+d)/2;
if(g*g==k)
break;
else if(g*g<k)
s=g;
else
d=g;
}
if(g*g>k)
g--;
if(g*g==k)
fout<<g;
else
{
p=k-g*g;
if(p<g+1)
fout<<p;
else
fout<<g+1;
}
}