{"id":313059,"date":"2020-11-12T21:00:33","date_gmt":"2020-11-12T21:00:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=313059"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=313059","title":{"rendered":"\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438 \u0437\u0430 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u0440\u0435\u043c\u044f"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<blockquote>\n<p><strong>\u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u0443\u0440\u0430&nbsp;<\/strong><a href=\"https:\/\/otus.pw\/nJPa\/\"><strong>&#171;\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430 \u0434\u043b\u044f Data Science&#187;<\/strong><\/a><strong> \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0432\u0430\u0441 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0434\u0435\u043c\u043e-\u0443\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0434\u0443\u0442 \u043d\u0430\u0448\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u044b.<\/strong><\/p>\n<\/p>\n<p>\u0410 \u043f\u0440\u044f\u043c\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<\/blockquote>\n<hr>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4ad\/325\/0bf\/4ad3250bf41416ce35860d9abf24c3ef\" width=\"875\" height=\"656\"><figcaption><\/figcaption><\/figure>\n<h3>\u041d\u0430\u0438\u0432\u043d\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u043c\u0435\u043d\u0438\u0442\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0430 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043b\u044e\u0434\u0435\u0439 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0437\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u041d\u043e \u043f\u043e\u0434 \u0441\u0438\u043b\u0443 \u043b\u0438 \u043d\u0430\u043c \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c? \u0414\u0430\u0436\u0435 \u043d\u0435 \u0441\u043e\u043c\u043d\u0435\u0432\u0430\u0439\u0442\u0435\u0441\u044c.<\/h3>\n<h3>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438?<\/h3>\n<p>\u042d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0440\u044f\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c n-\u0439 \u0447\u043b\u0435\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0443\u043c\u043c\u0443 \u0434\u0432\u0443\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432. \u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u0447\u043b\u0435\u043d\u0430 &#8212; 1 \u0438 1. \u0422\u0440\u0435\u0442\u0438\u0439 &#8212; 2, \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0439 &#8212; 3, \u0437\u0430\u0442\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 5, 8 \u0438 \u0442. \u0434.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/141\/825\/2d8\/1418252d883bb39ce8795cb5a425a7ae\" width=\"1600\" height=\"396\"><figcaption><\/figcaption><\/figure>\n<h3>\u041a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u043e?<\/h3>\n<p>\u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043b\u044e\u0434\u0438 \u0441\u043a\u043b\u043e\u043d\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430 \u0434\u0432\u0443\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0447\u043b\u0435\u043d\u0430\u0445. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f (\u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0437\u0432\u0435\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f n-1 \u0438 n-2).<\/p>\n<pre><code class=\"bash\">\/\/ calculates nth term of fibonacci, 1 indexed Procedure Fib_Naive(int n):     if(n &lt; 3):         return 1;         end_if     return Fib_Naive(n-1) + Fib_Naive(n-2) end_Fib_Naive<\/code><\/pre>\n<h3>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/h3>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0448\u0435 \u0431\u044b\u043b\u0430 \u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043b\u0438\u0431\u043e \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c, \u043b\u0438\u0431\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0434\u0432\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0447\u043b\u0435\u043d\u0430.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (<em>temp<\/em>) \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0447\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u044b, \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c\u044b\u0435 \u0432 \u0441\u0442\u0435\u043a, \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0441\u0431\u043e\u0440\u043a\u0438 \u043a\u043e\u0434\u0430).<\/p>\n<pre><code class=\"bash\">\/\/ calculates nth term of fibonacci, 1 indexed Procedure Fib(int n):         if(n &lt; 3): return 1;         int prev = 1;         int cur = 1;         for i = 3...n:             int temp = cur;             cur += prev;             prev = temp;         end_for return cur; end_Fib<\/code><\/pre>\n<h3>\u041d\u043e\u0432\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/h3>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043b\u0435\u0433\u043a\u0430 \u043e\u0441\u0432\u0435\u0436\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u0438\u0437 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0430\u043b\u0433\u0435\u0431\u0440\u044b.<\/p>\n<p>\u0412\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443, \u043f\u043e \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0435\u0434\u0438\u043d\u0438\u0446\u044b, \u0430 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0432\u043d\u044b \u043d\u0443\u043b\u044e:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/acf\/2cb\/a8d\/acf2cba8dce0406a355cb3e038faab3b\" alt=\"\u041f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043b\u044e\u0431\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0440\u0430\u0432\u043d\u043e \u0441\u0430\u043c\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0435, \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435.\" title=\"\u041f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043b\u044e\u0431\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0440\u0430\u0432\u043d\u043e \u0441\u0430\u043c\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0435, \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435.\" width=\"593\" height=\"146\"><figcaption>\u041f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043b\u044e\u0431\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0440\u0430\u0432\u043d\u043e \u0441\u0430\u043c\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0435, \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435.<\/figcaption><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438 \u0443\u043c\u043d\u043e\u0436\u0438\u043c \u0435\u0435 \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443, \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0442\u0435\u0445 \u0436\u0435 \u0434\u0432\u0443\u0445 \u0441\u0442\u0440\u043e\u043a \u0443 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f24\/20b\/1ab\/f2420b1ab2f343bf4b52a29151fbee62\" alt=\"\u0422\u0430\u043a\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 (\u0432 \u0446\u0435\u043d\u0442\u0440\u0435) \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a.\" title=\"\u0422\u0430\u043a\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 (\u0432 \u0446\u0435\u043d\u0442\u0440\u0435) \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a.\" width=\"574\" height=\"136\"><figcaption>\u0422\u0430\u043a\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 (\u0432 \u0446\u0435\u043d\u0442\u0440\u0435) \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a.<\/figcaption><\/figure>\n<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043d\u0438\u0436\u043d\u0435\u043c \u043f\u0440\u0430\u0432\u043e\u043c \u0443\u0433\u043b\u0443 \u0442\u0430\u043a\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u0438 \u0443\u043c\u043d\u043e\u0436\u0438\u043b\u0438 \u0435\u0435 \u043d\u0430 \u0432\u0435\u043a\u0442\u043e\u0440 2&#215;1 (a, b). \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442? \u041f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446, \u044d\u0442\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442 \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0430\u043c\u044b\u0439 \u043d\u0438\u0436\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0440\u0430\u0432\u043d\u044b\u043c (a + b).<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d51\/847\/8e5\/d518478e5b0f4423c5ffd4405e277892\" width=\"502\" height=\"140\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435. \u041f\u043e\u043c\u043d\u0438\u0442\u0435 \u043d\u0430\u0448\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438? \u0412 \u044d\u0442\u043e\u043c \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 <em>a <\/em>\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 (<em>(n-1)-\u0439) <\/em>\u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0430 <em>b <\/em>\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0439.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446 \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435.<\/p>\n<p>\u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043c\u044b \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0441\u043b\u0435\u0432\u0430 \u0432 n-\u044e \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0438 \u0443\u043c\u043d\u043e\u0436\u0438\u043c \u0435\u0435 \u043d\u0430 \u0432\u0435\u043a\u0442\u043e\u0440 (0, 1), \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c n-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7b1\/a19\/4b0\/7b1a194b0165cdc6adabe02be22c4177\" width=\"530\" height=\"144\"><figcaption><\/figcaption><\/figure>\n<h3>\u041e\u0442\u043a\u0443\u0434\u0430 \u0436\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c?<\/h3>\n<p>\u0414\u0432\u0430 \u0441\u043b\u043e\u0432\u0430: <a href=\"https:\/\/algorithmist.com\/wiki\/Repeated_squaring\"><u>\u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u0435 \u043a\u0432\u0430\u0434\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/u><\/a>. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u043c\u043d\u043e\u0436\u0430\u0442\u044c \u043b\u0435\u0432\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 n \u0440\u0430\u0437, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435.<\/p>\n<p>\u041c\u0430\u0442\u0440\u0438\u0446\u0430, \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u0430\u044f \u0432 8-\u044e \u0441\u0442\u0435\u043f\u0435\u043d\u044c, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0430 \u043f\u0443\u0442\u0435\u043c \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u0437\u0430\u0442\u0435\u043c \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f 4-\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442. \u042d\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c 8 \u0440\u0430\u0437 \u0443\u043c\u043d\u043e\u0436\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u0443.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8c5\/eee\/885\/8c5eee885dea0ec18a18d8b2518eb493\" width=\"525\" height=\"139\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0446\u0435\u043b\u044f\u0445 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u044b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0439, \u0432\u043e\u0442 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 Java (\u0430 \u043d\u0435 \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434, \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445).<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043d\u0435\u0442 \u043c\u0430\u0442\u0440\u0438\u0446, \u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0441\u0435-\u0440\u0430\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043a\u0432\u0430\u0434\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u0430\u043a \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0438\u0441\u043a\u043e\u043c\u043e\u0439 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"bash\">public int fib(int N) {         if(N == 0) return 0;         int[] sol = fibHelp(N);                  return sol[1];     }          public int[] fibHelp(int n) {         if(n == 1) {             return new int[] {0,1};         }         int m = n\/2;                  int[] temp = fibHelp(m);                  int fPrev = temp[0];         int fCur = temp[1];                  int prev = (fPrev * fPrev) + (fCur * fCur);         int cur = fCur * (2 * fPrev + fCur);         int next = prev + cur;                  if(n % 2 == 0) {              return new int[] {prev, cur};         }         else {             return new int[] {cur, next};         }     }<\/code><\/pre>\n<\/p>\n<p><strong>*\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: <\/strong>\u0425\u043e\u0442\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0441\u043e\u0431\u043b\u0430\u0437\u043d \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0438 \u0447\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043a\u0430\u043a \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f, \u0432\u0441\u0435 \u0436\u0435 \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043d\u044e\u0430\u043d\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c: \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0430\u043c\u043e\u0439 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u043a\u0438.<\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 <a href=\"https:\/\/hal.archives-ouvertes.fr\/hal-02070778\"><u>\u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0438\u0437 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f<\/u><\/a> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430 O(n log(n)). <em>\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438<\/em> \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u043c\u0443. \u041e\u0434\u043d\u0430\u043a\u043e \u0433\u043b\u0443\u0431\u0438\u043d\u0430 \u043d\u0430\u0448\u0435\u0439 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f, \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043a\u043e\u0434\u0430.<\/p>\n<hr>\n<blockquote>\n<p><a href=\"https:\/\/otus.pw\/nJPa\/\">\u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f<\/a> \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0432\u0435\u0431\u0438\u043d\u0430\u0440.<\/p>\n<\/blockquote>\n<\/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=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/527766\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/527766\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<blockquote>\n<p><strong>\u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u0443\u0440\u0430&nbsp;<\/strong><a href=\"https:\/\/otus.pw\/nJPa\/\"><strong>&#171;\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430 \u0434\u043b\u044f Data Science&#187;<\/strong><\/a><strong> \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0432\u0430\u0441 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0434\u0435\u043c\u043e-\u0443\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0434\u0443\u0442 \u043d\u0430\u0448\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u044b.<\/strong><\/p>\n<\/p>\n<p>\u0410 \u043f\u0440\u044f\u043c\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<\/blockquote>\n<hr>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u041d\u0430\u0438\u0432\u043d\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u043c\u0435\u043d\u0438\u0442\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0430 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043b\u044e\u0434\u0435\u0439 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0437\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u041d\u043e \u043f\u043e\u0434 \u0441\u0438\u043b\u0443 \u043b\u0438 \u043d\u0430\u043c \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c? \u0414\u0430\u0436\u0435 \u043d\u0435 \u0441\u043e\u043c\u043d\u0435\u0432\u0430\u0439\u0442\u0435\u0441\u044c.<\/h3>\n<h3>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438?<\/h3>\n<p>\u042d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0440\u044f\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c n-\u0439 \u0447\u043b\u0435\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0443\u043c\u043c\u0443 \u0434\u0432\u0443\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432. \u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u0447\u043b\u0435\u043d\u0430 &#8212; 1 \u0438 1. \u0422\u0440\u0435\u0442\u0438\u0439 &#8212; 2, \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0439 &#8212; 3, \u0437\u0430\u0442\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 5, 8 \u0438 \u0442. \u0434.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u041a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u043e?<\/h3>\n<p>\u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043b\u044e\u0434\u0438 \u0441\u043a\u043b\u043e\u043d\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430 \u0434\u0432\u0443\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0447\u043b\u0435\u043d\u0430\u0445. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f (\u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0437\u0432\u0435\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f n-1 \u0438 n-2).<\/p>\n<pre><code class=\"bash\">\/\/ calculates nth term of fibonacci, 1 indexed Procedure Fib_Naive(int n):     if(n &lt; 3):         return 1;         end_if     return Fib_Naive(n-1) + Fib_Naive(n-2) end_Fib_Naive<\/code><\/pre>\n<h3>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/h3>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0448\u0435 \u0431\u044b\u043b\u0430 \u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043b\u0438\u0431\u043e \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c, \u043b\u0438\u0431\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0434\u0432\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0447\u043b\u0435\u043d\u0430.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (<em>temp<\/em>) \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0447\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u044b, \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c\u044b\u0435 \u0432 \u0441\u0442\u0435\u043a, \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0441\u0431\u043e\u0440\u043a\u0438 \u043a\u043e\u0434\u0430).<\/p>\n<pre><code class=\"bash\">\/\/ calculates nth term of fibonacci, 1 indexed Procedure Fib(int n):         if(n &lt; 3): return 1;         int prev = 1;         int cur = 1;         for i = 3...n:             int temp = cur;             cur += prev;             prev = temp;         end_for return cur; end_Fib<\/code><\/pre>\n<h3>\u041d\u043e\u0432\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/h3>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043b\u0435\u0433\u043a\u0430 \u043e\u0441\u0432\u0435\u0436\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u0438\u0437 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0430\u043b\u0433\u0435\u0431\u0440\u044b.<\/p>\n<p>\u0412\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443, \u043f\u043e \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0435\u0434\u0438\u043d\u0438\u0446\u044b, \u0430 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0432\u043d\u044b \u043d\u0443\u043b\u044e:<\/p>\n<figure class=\"full-width\"><figcaption>\u041f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043b\u044e\u0431\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0440\u0430\u0432\u043d\u043e \u0441\u0430\u043c\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0435, \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435.<\/figcaption><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438 \u0443\u043c\u043d\u043e\u0436\u0438\u043c \u0435\u0435 \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443, \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0442\u0435\u0445 \u0436\u0435 \u0434\u0432\u0443\u0445 \u0441\u0442\u0440\u043e\u043a \u0443 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b:<\/p>\n<figure class=\"full-width\"><figcaption>\u0422\u0430\u043a\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 (\u0432 \u0446\u0435\u043d\u0442\u0440\u0435) \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a.<\/figcaption><\/figure>\n<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043d\u0438\u0436\u043d\u0435\u043c \u043f\u0440\u0430\u0432\u043e\u043c \u0443\u0433\u043b\u0443 \u0442\u0430\u043a\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u0438 \u0443\u043c\u043d\u043e\u0436\u0438\u043b\u0438 \u0435\u0435 \u043d\u0430 \u0432\u0435\u043a\u0442\u043e\u0440 2&#215;1 (a, b). \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442? \u041f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446, \u044d\u0442\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442 \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0430\u043c\u044b\u0439 \u043d\u0438\u0436\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0440\u0430\u0432\u043d\u044b\u043c (a + b).<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435. \u041f\u043e\u043c\u043d\u0438\u0442\u0435 \u043d\u0430\u0448\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438? \u0412 \u044d\u0442\u043e\u043c \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 <em>a <\/em>\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 (<em>(n-1)-\u0439) <\/em>\u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0430 <em>b <\/em>\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0439.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446 \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435.<\/p>\n<p>\u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043c\u044b \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0441\u043b\u0435\u0432\u0430 \u0432 n-\u044e \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0438 \u0443\u043c\u043d\u043e\u0436\u0438\u043c \u0435\u0435 \u043d\u0430 \u0432\u0435\u043a\u0442\u043e\u0440 (0, 1), \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c n-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<h3>\u041e\u0442\u043a\u0443\u0434\u0430 \u0436\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c?<\/h3>\n<p>\u0414\u0432\u0430 \u0441\u043b\u043e\u0432\u0430: <a href=\"https:\/\/algorithmist.com\/wiki\/Repeated_squaring\"><u>\u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u0435 \u043a\u0432\u0430\u0434\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/u><\/a>. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u043c\u043d\u043e\u0436\u0430\u0442\u044c \u043b\u0435\u0432\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 n \u0440\u0430\u0437, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435.<\/p>\n<p>\u041c\u0430\u0442\u0440\u0438\u0446\u0430, \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u0430\u044f \u0432 8-\u044e \u0441\u0442\u0435\u043f\u0435\u043d\u044c, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0430 \u043f\u0443\u0442\u0435\u043c \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u0437\u0430\u0442\u0435\u043c \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f 4-\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442. \u042d\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c 8 \u0440\u0430\u0437 \u0443\u043c\u043d\u043e\u0436\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u0443.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0446\u0435\u043b\u044f\u0445 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u044b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0439, \u0432\u043e\u0442 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 Java (\u0430 \u043d\u0435 \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434, \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445).<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043d\u0435\u0442 \u043c\u0430\u0442\u0440\u0438\u0446, \u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0441\u0435-\u0440\u0430\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043a\u0432\u0430\u0434\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u0430\u043a \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0438\u0441\u043a\u043e\u043c\u043e\u0439 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"bash\">public int fib(int N) {         if(N == 0) return 0;         int[] sol = fibHelp(N);                  return sol[1];     }          public int[] fibHelp(int n) {         if(n == 1) {             return new int[] {0,1};         }         int m = n\/2;                  int[] temp = fibHelp(m);                  int fPrev = temp[0];         int fCur = temp[1];                  int prev = (fPrev * fPrev) + (fCur * fCur);         int cur = fCur * (2 * fPrev + fCur);         int next = prev + cur;                  if(n % 2 == 0) {              return new int[] {prev, cur};         }         else {             return new int[] {cur, next};         }     }<\/code><\/pre>\n<\/p>\n<p><strong>*\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: <\/strong>\u0425\u043e\u0442\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0441\u043e\u0431\u043b\u0430\u0437\u043d \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0438 \u0447\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043a\u0430\u043a \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f, \u0432\u0441\u0435 \u0436\u0435 \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043d\u044e\u0430\u043d\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c: \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0430\u043c\u043e\u0439 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u043a\u0438.<\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 <a href=\"https:\/\/hal.archives-ouvertes.fr\/hal-02070778\"><u>\u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0438\u0437 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f<\/u><\/a> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430 O(n log(n)). <em>\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438<\/em> \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u043c\u0443. \u041e\u0434\u043d\u0430\u043a\u043e \u0433\u043b\u0443\u0431\u0438\u043d\u0430 \u043d\u0430\u0448\u0435\u0439 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f, \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043a\u043e\u0434\u0430.<\/p>\n<hr>\n<blockquote>\n<p><a href=\"https:\/\/otus.pw\/nJPa\/\">\u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f<\/a> \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0432\u0435\u0431\u0438\u043d\u0430\u0440.<\/p>\n<\/blockquote>\n<\/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=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/527766\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/527766\/<\/a><br \/><\/br><\/br><\/p>\n<\/hr>\n<\/div>\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-313059","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313059","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=313059"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313059\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=313059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=313059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=313059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}