Am studiat vreo 20-30 de cazuri si pentru toate codul de mai jos era bun, eu am gasit trei cazuri (cand e patrat perfect, cand nu e patrat perfect si e impar, cand e patrat perfect si e par):
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
ifstream f("chiftea.in");
ofstream g("chiftea.out");
int t,x,i;
int main()
{
f>>t;
for (i=1;i<=t;i++)
{f>>x;
if (sqrt(x)==(int)(sqrt(x)))
g<<x-(pow(sqrt(x)-2,2))+4<<"\n";
if (sqrt(x)!=(int)(sqrt(x))&&x%2==0)
g<<x+4<<"\n";
if (sqrt(x)!=(int)(sqrt(x))&&x%2==1)
g<<x+5<<"\n";
}
return 0;
}
