39=3*9+3+9
Is it not cute?
Let's attach the adjective
cute to all numbers equaling the sum of their digit augmented by the digits' product.
List all the cute numbers below 100.
Are there cute numbers bigger thann 100?
n pod sod
19 9 10
29 18 11
39 27 12
49 36 13
59 45 14
69 54 15
79 63 16
89 72 17
99 81 18
The only solutions.
The program tested up to 100,000.
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For n = 1 To 100000
DoEvents
nn = sod(n) + pod(n)
If n = nn Then
Text1.Text = Text1.Text & n & Str(pod(n)) & Str(sod(n)) & crlf
End If
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
Function sod(n)
s$ = LTrim(Str(n))
tot = 0
For i = 1 To Len(s$)
tot = tot + Val(Mid(s$, i, 1))
Next
sod = tot
End Function
Function pod(n)
s$ = LTrim(Str(n))
tot = 1
For i = 1 To Len(s$)
tot = tot * Val(Mid(s$, i, 1))
Next
pod = tot
End Function
|
Posted by Charlie
on 2016-07-21 10:36:42 |