title: Finding three integers such that their sum of cosine values become max
body: <p>There are three integers <code>x</code>, <code>y</code> and <code>z</code> (each of them >= 1) and a given upper bound integer <code>n</code> &lt; 10^6. Also, <code>n = x + y + z</code> and <code>output = cos(x) + cos(y) + cos(z)</code>.</p>
  
  <p>The exercise is to maximize <code>output</code>.</p>
  
  <p>I wrote a simple script for this, but the time complexity is O(n^3). Is there any way to simplify this?</p>
  
  <pre><code>from math import cos
  
  n = 50
  x = 1
  y = 1
  z = 1
  
  total = cos(x) + cos(y) + cos(z)
  
  for x in xrange(n):
      for y in xrange(n):
          for z in xrange(n):
              if x + y + z == n:
                  temp = cos(x) + cos(y) + cos(z)
                  if temp &gt; total: total = temp
  
  print round(total, 9) 
  </code></pre>