title: How can I generate three random integers that satisfy some condition?
body: <p>I'm a beginner in programming and I'm looking for a nice idea how to generate three integers that satisfy a condition.</p>
  <p>Example:</p>
  <p>We are given <code>n = 30</code>, and we've been asked to generate three integers a, b and c, so that <code>7*a + 5*b + 3*c = n</code>.
  I tried to use <code>for</code> loops, but it takes too much time and I have a maximum testing time of 1000 ms.</p>
  <p>I'm using Python 3.</p>
  <p>My attempt:</p>
  <pre><code>x = int(input())
  c = []
  k = []
  w = []
  for i in range(x):
      for j in range(x):
          for h in range(x):
             if 7*i + 5*j + 3*h = x:
                c.append(i)
                k.append(j)
                w.append(h)
  if len(c) == len(k) == len(w) 
      print(-1)
  else: 
      print(str(k[0]) + ' ' + str(c[0]) + ' ' + str(w[0]))
  </code></pre>