All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Maximizing the sum (Posted on 2016-11-16)
Let me provide some facts about a couple of integers m and n:

- One of them is a 3-digit number, the other is a 2-digit number
- One of them is divisible by 11
- One has all its digits distinct
- The last digit of m^3 equals the last digit of n
- The last digit of n^3 equals the last digit of m

a. Evaluate the maximum value of m+n.
b. What possible values can m*n reach?

 No Solution Yet Submitted by Ady TZIDON No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 the program Comment 4 of 4 |
(In reply to part b in more concise form by Charlie)

DefDbl A-Z
Dim crlf\$

Form1.Visible = True

Text1.Text = ""
crlf = Chr\$(13) + Chr\$(10)

For a = 100 To 999
For b = 10 To 99
If a Mod 11 = 0 Or b Mod 11 = 0 Then
astr\$ = LTrim(Str(a)): bstr\$ = LTrim(Str(b))
good = 0
If Mid(astr, 1, 1) <> Mid(astr, 2, 1) And Mid(astr, 1, 1) <> Mid(astr, 3, 1) And Mid(astr, 3, 1) <> Mid(astr, 2, 1) Then good = 1
If Mid(bstr, 1, 1) <> Mid(bstr, 2, 1) Then good = 1
If good Then
a3 = a * a * a: b3 = b * b * b
If a3 Mod 10 = b Mod 10 And a Mod 10 = b3 Mod 10 Then
Text1.Text = Text1.Text & a & Str(b) & "       "
Text1.Text = Text1.Text & mform(a + b, "###0") & mform(a * b, "#####0") & "        "
Text1.Text = Text1.Text & mform(a3, "##########0") & mform(b3, "######0") & crlf
If a + b > maxsum Then maxsum = a + b: mxsa = a: mxsb = b
If a * b > maxprod Then maxprod = a * b: mxpa = a: mxpb = b
End If
End If
End If
DoEvents
Next
Next

Text1.Text = Text1.Text & maxsum & Str(mxsa) & Str(mxsb) & crlf
Text1.Text = Text1.Text & maxprod & Str(mxpa) & Str(mxpb) & crlf
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

 Posted by Charlie on 2016-11-16 10:22:00

 Search: Search body:
Forums (1)