#include<iostream>
#include<iomanip>
#include <cmath>
using namespace std;
float my_sqrt(long long n,int p)
{
int start = 0;
int end = n;
float ans;
int mid;
while(start <= end)
{
mid = (start+end)/2;
if(mid*mid < n)
start = mid + 1;
else if(mid*mid > n)
end = mid - 1;
else
{
ans = mid;
break;
}
}
float increment = 0.1;
for(int i = 0; i < p;i++)
{
while(ans * ans <= n)
{
ans += increment;
}
ans -= increment;
increment /= 10;
}
return ans;
}
int main()
{
long long int n;
for(int i = 0; i < 100; ++i)
{
cout << fixed << setprecision(4) << sqrt(i) << " ";
cout << fixed << setprecision(4) << my_sqrt(i,4) << " ";
cout << fixed << setprecision(6) << my_sqrt(i,4) << endl;
}
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGlvbWFuaXA+CiNpbmNsdWRlIDxjbWF0aD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKZmxvYXQgbXlfc3FydChsb25nIGxvbmcgbixpbnQgcCkKewogICAgaW50IHN0YXJ0ID0gMDsKICAgIGludCBlbmQgPSBuOwogICAgZmxvYXQgYW5zOwogICAgaW50IG1pZDsKICAgIHdoaWxlKHN0YXJ0IDw9IGVuZCkKICAgIHsKICAgICAgICBtaWQgPSAoc3RhcnQrZW5kKS8yOwogICAgICAgIGlmKG1pZCptaWQgPCBuKQogICAgICAgICAgICBzdGFydCA9IG1pZCArIDE7CiAgICAgICAgZWxzZSBpZihtaWQqbWlkID4gbikKICAgICAgICAgICAgZW5kID0gbWlkIC0gMTsKICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBhbnMgPSBtaWQ7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgIH0KICAgIGZsb2F0IGluY3JlbWVudCA9IDAuMTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBwO2krKykKICAgIHsKICAgICAgICB3aGlsZShhbnMgKiBhbnMgPD0gbikKICAgICAgICB7CiAgICAgICAgICAgIGFucyArPSBpbmNyZW1lbnQ7CiAgICAgICAgfQogICAgICAgIGFucyAtPSBpbmNyZW1lbnQ7CiAgICAgICAgaW5jcmVtZW50IC89IDEwOwogICAgfQogICAgcmV0dXJuIGFuczsKfQppbnQgbWFpbigpCnsKICAgIGxvbmcgbG9uZyBpbnQgbjsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCAxMDA7ICsraSkKICAgIHsKICAgICAgICBjb3V0IDw8IGZpeGVkIDw8IHNldHByZWNpc2lvbig0KSA8PCBzcXJ0KGkpIDw8ICIgIjsKICAgICAgICBjb3V0IDw8ICBmaXhlZCA8PCBzZXRwcmVjaXNpb24oNCkgPDwgbXlfc3FydChpLDQpIDw8ICIgIjsKICAgICAgICBjb3V0IDw8ICBmaXhlZCA8PCBzZXRwcmVjaXNpb24oNikgPDwgbXlfc3FydChpLDQpIDw8IGVuZGw7CiAgICB9Cn0=