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

Home > Just Math
Composite Sum Satisfaction (Posted on 2014-11-11) Difficulty: 3 of 5
Determine the largest even positive integer that cannot be written as the sum of two odd composite positive integers.

No Solution Yet Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 1 of 4
DefDbl A-Z
Dim crlf$, fct(20, 1)
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

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 = 2 To 200000 Step 2
  found = 0
  For a = 9 To n - 9 Step 2
   good1 = 0: good2 = 0
   b = n - a
   f1 = factor(a)
   If f1 > 1 Or fct(1, 1) > 1 Then good1 = 1
   f2 = factor(b)
   If f2 > 1 Or fct(1, 1) > 1 Then good2 = 1
   If good1 And good2 Then
     ' Text1.Text = Text1.Text & n & Str(a) & Str(b) & crlf
     found = 1
     DoEvents
     Exit For
   End If
  Next
  If found = 0 Then
    Text1.Text = Text1.Text & n & crlf
  End If
 Next

 Text1.Text = Text1.Text & "done" & crlf
 
End Sub

Function factor(num)
 diffCt = 0: good = 1
 n = Abs(num): If n > 0 Then limit = Sqr(n) Else limit = 0
 If limit <> Int(limit) Then limit = Int(limit + 1)
 dv = 2: GoSub DivideIt
 dv = 3: GoSub DivideIt
 dv = 5: GoSub DivideIt
 dv = 7
 Do Until dv > limit
   GoSub DivideIt: dv = dv + 4 '11
   GoSub DivideIt: dv = dv + 2 '13
   GoSub DivideIt: dv = dv + 4 '17
   GoSub DivideIt: dv = dv + 2 '19
   GoSub DivideIt: dv = dv + 4 '23
   GoSub DivideIt: dv = dv + 6 '29
   GoSub DivideIt: dv = dv + 2 '31
   GoSub DivideIt: dv = dv + 6 '37
   If INKEY$ = Chr$(27) Then s$ = Chr$(27): Exit Function
 Loop
 If n > 1 Then diffCt = diffCt + 1: fct(diffCt, 0) = n: fct(diffCt, 1) = 1
 factor = diffCt
 Exit Function

DivideIt:
 cnt = 0
 Do
  q = Int(n / dv)
  If q * dv = n And n > 0 Then
    n = q: cnt = cnt + 1: If n > 0 Then limit = Sqr(n) Else limit = 0
    If limit <> Int(limit) Then limit = Int(limit + 1)
   Else
    Exit Do
  End If
 Loop
 If cnt > 0 Then
   diffCt = diffCt + 1
   fct(diffCt, 0) = dv
   fct(diffCt, 1) = cnt
 End If
 Return
End Function

finds those that cannot be done:

2
4
6
8
10
12
14
16
20
22
26
28
32
38

so the largest is 38.

In fact the answer is the same if the rules of the puzzle are actually followed, that is, the two composite addends need to be odd:

2
4
6
8
10
12
14
16
20
22
26
28
32
38

The corrected area of code is:

   f1 = factor(a)
   If (f1 > 1 Or fct(1, 1) > 1) And fct(1, 0) <> 2 Then good1 = 1
   f2 = factor(b)
   If (f2 > 1 Or fct(1, 1) > 1) And fct(1, 0) <> 2 Then good2 = 1

The ones that can be done in the range below 38 are:

18=9+9
24=9+15
30=9+21
34=9+25
36=9+27

and the remaining even numbers through 100:

40=15+25
42=9+33
44=9+35
46=21+25
48=9+39
50=15+35
52=25+27
54=9+45
56=21+35
58=9+49
60=9+51
62=27+35
64=9+55
66=9+57
68=33+35
70=15+55
72=9+63
74=9+65
76=21+55
78=9+69
80=15+65
82=25+57
84=9+75
86=9+77
88=25+63
90=9+81
92=15+77
94=9+85
96=9+87
98=21+77
100=9+91


  Posted by Charlie on 2014-11-11 10:34:13
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information