食堂内不足100个鸡蛋,6个6个地数,最后多4个,8个8个地数,最后多6个,你知道到底有多少个鸡蛋
食堂内不足100个鸡蛋,6个6个地数,最后多4个,8个8个地数,最后多6个,你知道到底有多少个鸡蛋
答案是:22,46,70,94
可以用程序实现:
Dim intTotal As Integer, intA As Integer, intB As Integer, intC As Integer, intD As Integer
intTotal = Val(txtTotal)
intA = Val(txtA)
intB = Val(txtB)
intC = Val(txtC)
intD = Val(txtD)
Dim i As Integer, j As Integer
Static intResult As Integer
intResult = 0
For i = 0 To intTotal / intA
For j = 0 To intTotal / intC
If i = CInt(j * intC + intD - intB) / intA Then
Load frmResult
intResult = intResult + 1
frmResult.txtResult.Text = frmResult.txtResult.Text & intResult & "·鸡蛋个数是:" & i * intA + intB & vbCrLf
End If
Next j
Next i
frmResult.Caption = "鸡蛋个数有" & intResult & "种可能"
frmResult.txtResult.Text = Left(frmResult.txtResult.Text, Len(frmResult.txtResult.Text) - 1)
frmResult.Show vbModal
这个答案远远不如前三楼的简洁,不过如果题目改成“A个A个地数,最后多B个,C个C个地数,最后多D个”(A,B,C,D是题目给定的数)时,上述代码就能略有优势了。
这题目其实挺简单,我写一写算式(多4个,多6个,也都是少2个)“*”代表乘
(6,8)=6*8=24 24*4=96(个) 96+2=98(个)
答:有98个鸡蛋
如果加上2个,则6个6个,8个8个地数,最后都正好
6,8的最小公倍数为24
鸡蛋数为:24n-2,(n=1,2,3,4)
n=1,24n-2=22
n=2,24n-2=46
n=3,24n-2=70
n=4,24n-2=94
6个6个地数,最后多4个,8个8个地数,最后多6个,
也就是说
6个6个地数,最后少2个,8个8个地数,最后也少2个,
所以鸡蛋的个数是6和8的公倍数减2个
6和8的最小公倍数是24,公倍数是24,48,72,96,120.....
已知鸡蛋的个数不足100个鸡蛋,
所以鸡蛋的个数是22个,或46个,或70个,或94个.