18! is a 16-digit number, so checking the sums of pairs of factorials up to that of 18 for whether the sum is a square will be sufficient. Only five cases of sums of two factorials result in perfect squares:
a b sqrt a!+b!
1 4 5 25
1 5 11 121
1 7 71 5041
2 2 2 4
4 5 12 144
In the sqrt column (that is, the square root of the sum of factorials), only two of the numbers are successive: the 11 and 12 of the original set from the puzzle.
For a = 1 To 18
For b = a To 18
tot = fact(a) + fact(b)
sr = Int(Sqr(tot) + 0.5)
If sr * sr = tot Then
Text1.Text = Text1.Text & a & Str(b) & " " & sr & Str(sr * sr) & crlf
DoEvents
End If
Next
Next
Function fact(x)
f = 1
For i = 2 To x
f = f * i
Next
fact = f
End Function
Of course, upon reading Dej Mar's answer, I realize I neglected the negative square roots.
|
Posted by Charlie
on 2015-04-07 14:34:22 |