The numbers
A &
B: 1. Comprise 5 distinct digits each.
2. Jointly use all 10 digits.
3. None has a leading zero.
4.
Both
A^2 and
B^2 are 10-pandigital numbers.
Find the values of
A and
B.
A B A^2 B^2
35172 60984 1237069584 3719048256
57321 60984 3285697041 3719048256
58413 96702 3412078569 9351276804
59403 76182 3528716409 5803697124
A and B can of course be switched.
DefDbl A-Z
Dim crlf$, validnum(1000) As String, validnums
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For a = 1 To 9
For b = 0 To 9
If b <> a Then
For c = 0 To 9
If c <> a And c <> b Then
For d = 0 To 9
If d <> a And d <> b And d <> c Then
For e = 0 To 9
If e <> a And e <> b And e <> c And e <> d Then
n = 10000 * a + 1000 * b + 100 * c + 10 * d + e
nsq = n * n
s$ = LTrim(Str(nsq))
If Len(s) = 10 Then
good = 1
For i = 2 To 10
If InStr(s, Mid(s, i, 1)) < i Then good = 0: Exit For
Next
If good Then
validnums = validnums + 1
validnum(validnums) = n
End If
DoEvents
End If
End If
Next e
End If
Next d
End If
Next c
End If
Next b
Next a
For i = 1 To validnums - 1
For j = i + 1 To validnums
concat$ = validnum(i) + validnum(j)
good = 1
For k = 2 To 10
If InStr(concat, Mid(concat, k, 1)) < k Then good = 0: Exit For
Next
If good Then
Text1.Text = Text1.Text & validnum(i) & " " & validnum(j) & " "
Text1.Text = Text1.Text & validnum(i) ^ 2 & " " & validnum(j) ^ 2 & crlf
End If
Next
Next
Text1.Text = Text1.Text & crlf & validnums & " done"
End Sub
|
Posted by Charlie
on 2018-01-26 14:13:29 |