3888 * 2 = 7776
上式的等號兩邊都有一個四位數,注意左邊的3888的後三位數相同,而右邊的7776卻是前三位數相同。因為發現這兩個數的變化頗具特色(本來是後三位相同,乘以2後卻變成前三位相同),所以這時也突發奇想,問自己這個問題:「上面等式兩邊的四位數,除了原本的3888與7776這一組數,可以構成一組型如(abbb,cccd)的四位數組解之外,是否還有其他的四位數組解呢?」
也就是說,請找出下面包含兩個未知的四位數abbb,cccd的數學式子的解:
abbb *2 = cccd
上面的abbb與cccd加上底線,是強調它們是十進位的寫法。其中,a,c是1~9的正整數,b,d是0~9的整數。為了避免出現像1111×2=2222或3333×2=6666這樣子的例子出現,我們規定a與b不同,且c與d也不同。
請將解答輸出於out1.txt,若無其它解,則寫「無」。
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\out.txt" For Output As #1
For i = 1000 To 9999
one = i
two = i * 2
If (Mid(one, 1, 1) <> Mid(one, 2, 1)) And (Mid(one, 2, 1) = Mid(one, 3, 1)) And (Mid(one, 3, 1) = Mid(one, 4, 1)) And (Mid(two, 4, 1) <> Mid(two, 3, 1)) And (Mid(two, 3, 1) = Mid(two, 2, 1)) And (Mid(two, 3, 1) = Mid(two, 1, 1)) Then Print #1, i & "*2=" & i * 2
Next
Close #1
End
End Sub
Dim g, q As Integer
回覆刪除Dim t As Boolean
Private Sub Form_Load()
Me.Hide
Open App.Path & "\out.txt" For Output As #2
For i = 1 To 9
For j = 0 To 9
If i <> j Then
t = True
g = Val(i & j & j & j): q = g * 2
For w = 2 To 3
If Val(Mid(q, 1, 1)) <> Val(Mid(q, w, 1)) Then t = False: Exit For
Next w
If t = True Then Print #2, g & "* 2 = " & q: ans = ans + 1
End If
Next j
Next i
If ans = 0 Then Print #2, "無"
Close #2
End
End Sub