You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lavos/cap3/work14.go

23 lines
518 B

5 months ago
package cap3
import "math"
func Work14() []int {
resultSet := make([]int, 0)
for num := 100; num <= 999; num++ {
// 开方取整,再平方判,断是否能获得原来的数,来识别是否为完全平方数
intSqrt := int(math.Sqrt(float64(num)) + 0.5)
if intSqrt*intSqrt != num {
continue
}
// num的百位,十位,个位数,其中有相等即可
a, b, c := num/100, num%100/10, num%10
if a == b || a == c || b == c {
resultSet = append(resultSet, num)
}
}
return resultSet
}