<i id='8iGUG'><tr id='8iGUG'><dt id='8iGUG'><q id='8iGUG'><span id='8iGUG'><b id='8iGUG'><form id='8iGUG'><ins id='8iGUG'></ins><ul id='8iGUG'></ul><sub id='8iGUG'></sub></form><legend id='8iGUG'></legend><bdo id='8iGUG'><pre id='8iGUG'><center id='8iGUG'></center></pre></bdo></b><th id='8iGUG'></th></span></q></dt></tr></i><div id='8iGUG'><tfoot id='8iGUG'></tfoot><dl id='8iGUG'><fieldset id='8iGUG'></fieldset></dl></div>

      <small id='8iGUG'></small><noframes id='8iGUG'>

      <legend id='8iGUG'><style id='8iGUG'><dir id='8iGUG'><q id='8iGUG'></q></dir></style></legend>
      • <bdo id='8iGUG'></bdo><ul id='8iGUG'></ul>
      <tfoot id='8iGUG'></tfoot>

      1. 有效地获得给定数字的所有除数

        时间:2023-08-03
      2. <small id='EcJfk'></small><noframes id='EcJfk'>

        <tfoot id='EcJfk'></tfoot>

          <tbody id='EcJfk'></tbody>
      3. <i id='EcJfk'><tr id='EcJfk'><dt id='EcJfk'><q id='EcJfk'><span id='EcJfk'><b id='EcJfk'><form id='EcJfk'><ins id='EcJfk'></ins><ul id='EcJfk'></ul><sub id='EcJfk'></sub></form><legend id='EcJfk'></legend><bdo id='EcJfk'><pre id='EcJfk'><center id='EcJfk'></center></pre></bdo></b><th id='EcJfk'></th></span></q></dt></tr></i><div id='EcJfk'><tfoot id='EcJfk'></tfoot><dl id='EcJfk'><fieldset id='EcJfk'></fieldset></dl></div>

          <bdo id='EcJfk'></bdo><ul id='EcJfk'></ul>
          <legend id='EcJfk'><style id='EcJfk'><dir id='EcJfk'><q id='EcJfk'></q></dir></style></legend>

                  本文介绍了有效地获得给定数字的所有除数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  根据这个帖子,我们可以通过以下代码得到一个数的所有约数.

                  According to this post, we can get all divisors of a number through the following codes.

                  for (int i = 1; i <= num; ++i){
                      if (num % i == 0)
                          cout << i << endl;
                  }
                  

                  例如24的除数是1 2 3 4 6 8 12 24.

                  搜索了一些相关的帖子,没有找到好的解决办法.有什么有效的方法可以做到这一点吗?

                  After searching some related posts, I did not find any good solutions. Is there any efficient way to accomplish this?

                  我的解决方案:

                  1. 通过这个解决方案.
                  2. 获取这些质因数的所有可能组合.

                  然而,这似乎不是一个好方法.

                  However, it doesn't seem to be a good one.

                  推荐答案

                  因素是成对的.1 and 24, 2 and 12, 3 and 846.

                  Factors are paired. 1 and 24, 2 and 12, 3 and 8, 4 and 6.

                  算法的改进可能是迭代到 num 的平方根,而不是一直到 num,然后使用 计算配对因子num/i.

                  An improvement of your algorithm could be to iterate to the square root of num instead of all the way to num, and then calculate the paired factors using num / i.

                  这篇关于有效地获得给定数字的所有除数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:三次和 catmull 样条对图像的影响 下一篇:C++ 定点库?

                  相关文章

                  最新文章

                  <i id='nwQUs'><tr id='nwQUs'><dt id='nwQUs'><q id='nwQUs'><span id='nwQUs'><b id='nwQUs'><form id='nwQUs'><ins id='nwQUs'></ins><ul id='nwQUs'></ul><sub id='nwQUs'></sub></form><legend id='nwQUs'></legend><bdo id='nwQUs'><pre id='nwQUs'><center id='nwQUs'></center></pre></bdo></b><th id='nwQUs'></th></span></q></dt></tr></i><div id='nwQUs'><tfoot id='nwQUs'></tfoot><dl id='nwQUs'><fieldset id='nwQUs'></fieldset></dl></div>

                  • <bdo id='nwQUs'></bdo><ul id='nwQUs'></ul>

                  <small id='nwQUs'></small><noframes id='nwQUs'>

                • <tfoot id='nwQUs'></tfoot>

                      <legend id='nwQUs'><style id='nwQUs'><dir id='nwQUs'><q id='nwQUs'></q></dir></style></legend>