Is there a fast and simple way to write a program in C#, that finds out if a big (something like 25 digits big) number is a perfect square or not?
Perfect squares are the numbers: 0^2=0,1^2=1,2^2=4,3^2=9,4^2=16,...
Is there a fast and simple way to write a program in C#, that finds out if a big (something like 25 digits big) number is a perfect square or not?
Perfect squares are the numbers: 0^2=0,1^2=1,2^2=4,3^2=9,4^2=16,...
You can not convert any 25 digit number into ulong or long or int. But you can try if the number is ulong
public bool test(ulong num)
{ var sqrt = Math.Sqrt(num);
double dbl = Convert.ToDouble(sqrt);
long dblint = Convert.ToInt64(sqrt);
if (dbl == dblint)
{
return true;
}
return false;
}