3位数的平方数就那么多,从11^2到31^2穷举判断就好
///
/// 轮询3位平方数
///
static void searchNum()
{
for (int i = 11; i <= 29; i++)
{
for (int j = i + 1; j <= 30; j++)
{
for (int k = j + 1; k <= 31; k++)
{
if (checkNum(i * i, j * j, k * k))
{
Console.WriteLine("符合解:" + (i * i) + "," + (j * j) + "," + (k * k));
}
}
}
}
}
///
/// 判断3个三位数是否为不同数字组成
///
///
///
///
///
static bool checkNum(int num1, int num2, int num3)
{
int[] list = new int[9];
list[0] = num1 / 100;
list[1] = (num1 % 100) / 10;
list[2] = num1 % 10;
list[3] = num2 / 100;
list[4] = (num2 % 100) / 10;
list[5] = num2 % 10;
list[6] = num3 / 100;
list[7] = (num3 % 100) / 10;
list[8] = num3 % 10;
for (int i = 0; i < list.Length - 1; i++)
{
for (int j = i + 1; j < list.Length; j++)
{
if (list[i] == list[j])
{
return false;
}
}
}
return true;
}
用循环穷举三位数,筛选平方数条件
什么是平方数