N is a positive integer. S(N) denotes the sum of digits of N and P(N) denotes the product of digits of N.
Determine the values of N given that: N = 2*S(N)*P(N)
Private Sub Form_Load()
ChDir "C:\Program Files (x86)\DevStudio\VB\projects\flooble"
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
For n = 4 To 10000000 Step 4
If n = 2 * sod(n) * pod(n) Then
Text1.Text = Text1.Text & n & crlf
End If
DoEvents
Next
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))
prod = 1
For i = 1 To Len(s$)
prod = prod * Val(Mid(s$, i, 1))
Next
pod = prod
End Function
finds three solutions:
12
216
432
|
Posted by Charlie
on 2014-12-31 12:14:30 |