title: Self numbers in c++
body: <p>Hey, my friends and I are trying to beat each other's runtimes for generating "<a href="http://en.wikipedia.org/wiki/Self_number" rel="noreferrer">Self Numbers</a>" between 1 and a million.  I've written mine in c++ and I'm still trying to shave off precious time.</p>
  
  <p>Here's what I have so far,</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  bool v[1000000];
  int main(void) {
    long non_self = 0;
    for(long i = 1; i &lt; 1000000; ++i) {
      if(!(v[i])) std::cout &lt;&lt; i &lt;&lt; '\n';
      non_self = i + (i%10) + (i/10)%10 + (i/100)%10 + (i/1000)%10 + (i/10000)%10 +(i/100000)%10;
      v[non_self] = 1;
    }
    std::cout &lt;&lt; "1000000" &lt;&lt; '\n';
    return 0;
  }
  </code></pre>
  
  <p>The code works fine now, I just want to optimize it.
  Any tips? Thanks.</p>