title: What's the fastest way to find the factors of a number in c++?
body: <p>I have been struggling for speed and haven't found anything useful online. I'm also using boost::multiprecision 1024 bit integers. What's the fastest possible way to find all of the multiples for such large numbers?</p>
  <p>I have tried:</p>
  <ul>
  <li>looping from 1 to square root of the number</li>
  <li>incrementing by 2 if the number is odd</li>
  <li>keeping everything I can out of the loop</li>
  <li>compiling in release mode (vs2019)</li>
  </ul>
  <p>Here's my code so far.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;time.h&gt;
  #include &lt;boost/multiprecision/cpp_int.hpp&gt;
  
  using namespace std;
  using namespace boost::multiprecision;
  
  void multiples()
  {
      __int64 startthing, endthing;
      __int64 freq = _Query_perf_frequency();
  
      int1024_t divisor = 0, thing = 0;
  
      while (1)
      {
          //displayer.join();
          cout &lt;&lt; &quot;\nEnter a number\n&quot;;
          cin &gt;&gt; thing;
  
          if (thing == 0 &amp;&amp; !cin.fail())
              break;
          cout &lt;&lt; endl;
  
          while (cin.fail())
          {
              cout &lt;&lt; &quot;I said integer you rule breaker\n&quot;;
  
              // get rid of failure state
              cin.clear();
              cin.ignore(numeric_limits&lt;streamsize&gt;::max(), '\n');
              cin &gt;&gt; thing;
          }
  
          int1024_t limit = sqrt(thing);
          int1024_t step = (thing &amp; 1 ? 2 : 1); // odd number = odd factors
          startthing = _Query_perf_counter();   // start timer
  
          for (int1024_t i = 1; i &lt;= limit; i += step) 
          {
              if ((thing % i) == 0)
              {
                  divisor = thing / i;
                  cout &lt;&lt; i &lt;&lt; &quot;, &quot; &lt;&lt; divisor &lt;&lt; &quot;\n&quot;;
              }
          }
          endthing = _Query_perf_counter();
  
          cout &lt;&lt; &quot;\nThat took &quot; &lt;&lt; (endthing - startthing) / (double)freq &lt;&lt; &quot; seconds.\n&quot;;
      }
  }
  </code></pre>