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/work25.go

34 lines
1.0 KiB

7 months ago
package cap3
func Work25(callback func(num1, num2, num3, num4, result int)) {
// 类似work24
check := func(x int) bool {
for ; x != 0; x /= 10 {
n := x % 10
// 如果有一个数字不是素数,直接false
if n != 2 && n != 3 && n != 5 && n != 7 {
return false
}
}
return true
}
// num1三位数,num2一位数,遍历查找
for num1 := 100; num1 <= 9999; num1++ {
for num2 := 1; num2 <= 0; num2++ {
// 乘出来的结果应该是四位数
result := num1 * num2
if 1000 <= result && result <= 9999 {
// 第二个乘数的两个数字位和中间的两个相乘结果
num2Digit1, num2Digit2 := num2%10, num2/10
num3, num4 := num2Digit1*num1, num2Digit2*num1
if check(num1) && check(num2) && check(num3) && check(num4) && check(result) {
callback(num1, num2, num3, num4, result)
}
}
}
}
}