{"id":255234,"date":"2015-04-14T21:04:02","date_gmt":"2015-04-14T17:04:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=255234"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=255234","title":{"rendered":"\u0414\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b\u0430"},"content":{"rendered":"<p> \t\t\t\u041f\u043e\u043d\u044f\u0442\u0438\u0435 \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0432\u0441\u0435\u043c. \u042d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 1 \u0434\u043e N \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e: N! = 1 * 2 * 3 *\u2026 * N. \u0424\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b \u2014 \u0431\u044b\u0441\u0442\u0440\u043e\u0440\u0430\u0441\u0442\u0443\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0443\u0436\u0435 \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 N \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 N! \u0438\u043c\u0435\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0430\u0449\u0438\u0445 \u0446\u0438\u0444\u0440.<\/p>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u044f\u0437\u044b\u043a, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0434\u043b\u0438\u043d\u043d\u0443\u044e \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u043a\u0443. \u042f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c C#, \u043d\u043e \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u0443\u0441\u043f\u0435\u0445\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c Java \u0438\u043b\u0438 Python.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0435 \u043d\u0430\u0438\u0432\u043d\u043e\u0439) \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b\u0430:<\/p>\n<pre><code class=\"cs\">static BigInteger FactNaive(int n) {     BigInteger r = 1;     for (int i = 2; i &lt;= n; i++)         r *= i;     return r;             } <\/code><\/pre>\n<p>  \u041d\u0430 \u043c\u043e\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u044d\u0442\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 1,7 \u0441\u0435\u043a\u0443\u043d\u0434 \u0434\u043b\u044f N=50000.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0434\u0432\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043d\u0430\u0438\u0432\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u0435\u0440\u0432\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0442\u043e\u043c \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438, \u0447\u0442\u043e \u0434\u043b\u0438\u043d\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0434\u043b\u0438\u043d\u044b \u0443\u043c\u043d\u043e\u0436\u0430\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435, \u0447\u0435\u043c \u0434\u043b\u0438\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0443\u043c\u043d\u043e\u0436\u0430\u0442\u044c \u043d\u0430 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 (\u043a\u0430\u043a \u0432 \u043d\u0430\u0438\u0432\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438). \u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0431\u044b\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0434\u043b\u0438\u043d\u044b.<\/p>\n<p>  \u041f\u0443\u0441\u0442\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 L \u0434\u043e R, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u0435\u0433\u043e \u043a\u0430\u043a P(L, R). \u0420\u0430\u0437\u0434\u0435\u043b\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u043e\u0442 L \u0434\u043e R \u043f\u043e\u043f\u043e\u043b\u0430\u043c \u0438 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c P(L, R) \u043a\u0430\u043a P(L, M) * P(M + 1, R), \u0433\u0434\u0435 M \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u043c\u0435\u0436\u0434\u0443 L \u0438 R, M = (L + R) \/ 2. \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0434\u043b\u0438\u043d\u044b. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u044c\u0435\u043c P(L, M) \u0438 P(M + 1, R). \u0411\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u044d\u0442\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e, \u043f\u043e\u043a\u0430 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0434\u0432\u0443\u0445 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0435\u0439. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e P(L, R) = L, \u0435\u0441\u043b\u0438 L \u0438 R \u0440\u0430\u0432\u043d\u044b, \u0438 P(L, R) = L * R, \u0435\u0441\u043b\u0438 L \u0438 R \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443. \u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 N! \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c P(2, N).<\/p>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0448 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043b\u044f N=10, \u043d\u0430\u0439\u0434\u0435\u043c P(2, 10):<\/p>\n<p>  P(2, 10)<br \/>  P(2, 6) * P(7, 10)<br \/>  ( P(2, 4) * P(5, 6) ) * ( P(7, 8) * P(9, 10) ) <br \/>  ( (P(2, 3) * P(4) ) * P(5, 6) ) * ( P(7, 8) * P(9, 10) )<br \/>  ( ( (2 * 3) * (4) ) * (5 * 6) ) * ( (7 * 8) * (9 * 10) )<br \/>  ( ( 6 * 4 ) * 30 ) * ( 56 * 90 )<br \/>  ( 24 * 30 ) * ( 5 040 )<br \/>  720 * 5 040<br \/>  3 628 800<\/p>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0435\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e, \u0433\u0434\u0435 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0443\u0437\u043b\u0430\u0445, \u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u0440\u043d\u0435.<\/p>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c:<\/p>\n<pre><code class=\"cs\">static BigInteger ProdTree(int l, int r) {     if (l &gt; r)         return 1;     if (l == r)          return l;     if (r - l == 1)         return (BigInteger)l * r;     int m = (l + r) \/ 2;     return ProdTree(l, m) * ProdTree(m + 1, r); }          static BigInteger FactTree(int n) {     if (n &lt; 0)         return 0;     if (n == 0)         return 1;     if (n == 1 || n == 2)         return n;     return ProdTree(2, n); }         <\/code><\/pre>\n<p>  \u0414\u043b\u044f N=50000 \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430 0,8 \u0441\u0435\u043a\u0443\u043d\u0434, \u0447\u0442\u043e \u0432\u0434\u0432\u043e\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u0432 \u043d\u0430\u0438\u0432\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0412\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0438. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438 N! \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0438 \u043e\u0442 2 \u0434\u043e N. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044c K \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432 N!, \u0442\u043e \u0435\u0441\u0442\u044c \u0443\u0437\u043d\u0430\u0435\u043c \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044f K \u0432 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 K-\u044b\u0439 \u0447\u043b\u0435\u043d \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f 1 * 2 * 3 *\u2026 * N \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d N \/ K. \u041d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 K<sup>2<\/sup>-\u044b\u0439 \u0447\u043b\u0435\u043d \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0435\u0449\u0435 \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f N \/ K + N \/ K<sup>2<\/sup>. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u043b\u044f K<sup>3<\/sup>, K<sup>4<\/sup> \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043f\u0440\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0435 K \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d N \/ K + N \/ K<sup>2<\/sup> + N \/ K<sup>3<\/sup> + N \/ K<sup>4<\/sup> +\u2026<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0434\u0432\u043e\u0439\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432 10! \u0414\u0432\u043e\u0439\u043a\u0443 \u0434\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u0442\u043e\u0440\u043e\u0439 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044c (2, 4, 6, 8 \u0438 10), \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u043a\u0438\u0445 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0435\u0439 10 \/ 2 = 5. \u0418\u0437 \u043d\u0438\u0445 \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0439 \u0434\u0430\u0435\u0442 \u0447\u0435\u0442\u0432\u0435\u0440\u043a\u0443 (2<sup>2<\/sup>), \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u043a\u0438\u0445 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0435\u0439 10 \/ 4 = 2 (4 \u0438 8). \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u043e\u0441\u044c\u043c\u043e\u0439 \u0434\u0430\u0435\u0442 \u0432\u043e\u0441\u044c\u043c\u0435\u0440\u043a\u0443 (2<sup>3<\/sup>), \u0442\u0430\u043a\u043e\u0439 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d 10 \/ 8 = 1 (8). \u0428\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c (2<sup>4<\/sup>) \u0438 \u0431\u043e\u043b\u0435\u0435 \u0443\u0436\u0435 \u043d\u0435 \u0434\u0430\u0435\u0442 \u043d\u0438 \u043e\u0434\u0438\u043d \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044c, \u0437\u043d\u0430\u0447\u0438\u0442, \u043f\u043e\u0434\u0441\u0447\u0435\u0442 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u044c. \u0421\u0443\u043c\u043c\u0438\u0440\u0443\u044f, \u043f\u043e\u043b\u0443\u0447\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043f\u0440\u0438 \u0434\u0432\u043e\u0439\u043a\u0435 \u0432 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438 10! \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d 10 \/ 2 + 10 \/ 4 + 10 \/ 8 = 5 + 2 + 1 = 8.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043f\u0440\u0438 3, 5 \u0438 7 \u0432 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438 10!, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f:<\/p>\n<p>  10! = 2<sup>8<\/sup> * 3<sup>4<\/sup> * 5<sup>2<\/sup> * 7<sup>1<\/sup> = 3 628 800<\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u043e\u0442 2 \u0434\u043e N, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A0%D0%B5%D1%88%D0%B5%D1%82%D0%BE_%D0%AD%D1%80%D0%B0%D1%82%D0%BE%D1%81%D1%84%D0%B5%D0%BD%D0%B0\">\u0440\u0435\u0448\u0435\u0442\u043e \u042d\u0440\u0430\u0442\u043e\u0441\u0444\u0435\u043d\u0430<\/a>:<\/p>\n<pre><code class=\"cs\">static BigInteger FactFactor(int n) {     if (n &lt; 0)         return 0;     if (n == 0)         return 1;     if (n == 1 || n == 2)         return n;     bool[] u = new bool[n + 1]; \/\/ \u043c\u0430\u0440\u043a\u0435\u0440\u044b \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u0442\u0430 \u042d\u0440\u0430\u0442\u043e\u0441\u0444\u0435\u043d\u0430     List&lt;Tuple&lt;int, int&gt;&gt; p = new List&lt;Tuple&lt;int, int&gt;&gt;(); \/\/ \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0438 \u0438 \u0438\u0445 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0441\u0442\u0435\u043f\u0435\u043d\u0435\u0439     for (int i = 2; i &lt;= n; ++i)         if (!u[i]) \/\/ \u0435\u0441\u043b\u0438 i - \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e         {             \/\/ \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0432 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438             int k = n \/ i;             int c = 0;             while (k &gt; 0)             {                 c += k;                 k \/= i;             }             \/\/ \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044c \u0438 \u0435\u0433\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u0435\u043f\u0435\u043d\u0438             p.Add(new Tuple&lt;int, int&gt;(i, c));              \/\/ \u043f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u0448\u0435\u0442\u043e                            int j = 2;             while (i * j &lt;= n)             {                 u[i * j] = true;                 ++j;             }         }     \/\/ \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b     BigInteger r = 1;     for (int i = p.Count() - 1; i &gt;= 0; --i)         r *= BigInteger.Pow(p[i].Item1, p[i].Item2);     return r; } <\/code><\/pre>\n<p>  \u042d\u0442\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0430\u043a\u0436\u0435 \u0442\u0440\u0430\u0442\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 0,8 \u0441\u0435\u043a\u0443\u043d\u0434 \u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 50000. \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/255761\/\"> http:\/\/habrahabr.ru\/post\/255761\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p> \t\t\t\u041f\u043e\u043d\u044f\u0442\u0438\u0435 \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0432\u0441\u0435\u043c. \u042d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 1 \u0434\u043e N \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e: N! = 1 * 2 * 3 *\u2026 * N. \u0424\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b \u2014 \u0431\u044b\u0441\u0442\u0440\u043e\u0440\u0430\u0441\u0442\u0443\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0443\u0436\u0435 \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 N \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 N! \u0438\u043c\u0435\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0430\u0449\u0438\u0445 \u0446\u0438\u0444\u0440.<\/p>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u044f\u0437\u044b\u043a, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0434\u043b\u0438\u043d\u043d\u0443\u044e \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u043a\u0443. \u042f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c C#, \u043d\u043e \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u0443\u0441\u043f\u0435\u0445\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c Java \u0438\u043b\u0438 Python.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0435 \u043d\u0430\u0438\u0432\u043d\u043e\u0439) \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b\u0430:<\/p>\n<pre><code class=\"cs\">static BigInteger FactNaive(int n) {     BigInteger r = 1;     for (int i = 2; i &lt;= n; i++)         r *= i;     return r;             } <\/code><\/pre>\n<p>  \u041d\u0430 \u043c\u043e\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u044d\u0442\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 1,7 \u0441\u0435\u043a\u0443\u043d\u0434 \u0434\u043b\u044f N=50000.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0434\u0432\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043d\u0430\u0438\u0432\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-255234","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/255234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=255234"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/255234\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=255234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=255234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=255234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}