S denotes the sum of the digits and P denotes the product of the nonzero digits.
It is observed that for the year 2016, S = 9 and P = 12, so that:
S:P = 3:4
Determine all years from 2000 to 3000 such that:
S:P = 3:4
(In reply to
No Subject by Ady TZIDON)
2016 and 2061 are missing from your list; of course the former was present in the puzzle itself, but not the latter.
year sod pod(nz)
2004 6 8
2016 9 12
2022 6 8
2040 6 8
2061 9 12
2106 9 12
2118 12 16
2160 9 12
2181 12 16
2202 6 8
2220 6 8
2400 6 8
2601 9 12
2610 9 12
2811 12 16
from
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For y = 2000 To 2999
DoEvents
If 4 * sod(y) = 3 * podnz(y) Then
Text1.Text = Text1.Text & y & mform(sod(y), "###0") & mform(podnz(y), "###0") & crlf
End If
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
Function mform$(x, t$)
a$ = Format$(x, t$)
If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
mform$ = a$
End Function
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 podnz(n)
s$ = LTrim(Str(n))
tot = 1
For i = 1 To Len(s$)
If Mid(s, i, 1) <> "0" Then tot = tot * Val(Mid(s$, i, 1))
Next
podnz = tot
End Function
|
Posted by Charlie
on 2016-08-23 19:52:39 |