solution 1
{=IFS(RC[-1]<4,-1,ISEVEN(RC[-1]),RC[-1]/2,1,MAX(IF(MOD(RC[-1],(ROW(R1C:INDEX(C,SQRT(RC[-1]/4)))*2)+1)=0,RC[-1]/(ROW(R1C:INDEX(C,SQRT(RC[-1]/4)))*2+1), -1)))}
solution 2
{=IF(RC[-1]<4;-1;MAX(IF(MOD(RC[-1]; ROW(R2C:INDEX(C;SQRT(RC[-1]))))=0; RC[-1]/ROW(R2C:INDEX(C;SQRT(RC[-1]))); -1)))}
There is an entry on one of my spreadsheets were solution number one produces an error which I have not been able to correct. But this formula has worked perfectly correctly in 3 other test spreadsheets.
Solution 2 also is working correctly and produces exactly the same result.
Thank you fro your help.
Andy