• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            為生存而奔跑

               :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

            留言簿(5)

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 330206
            • 排名 - 74

            最新評論

            閱讀排行榜

            評論排行榜

            http://code.google.com/codejam/contest/dashboard?c=32016#s=p2
            Problem

            In this problem, you have to find the last three digits before the decimal point for the number (3 + √5)n.

            For example, when n = 5, (3 + √5)5 = 3935.73982... The answer is 935.

            For n = 2, (3 + √5)2 = 27.4164079... The answer is 027.

            Input

            The first line of input gives the number of cases, T. T test cases follow, each on a separate line. Each test case contains one positive integer n.

            Output

            For each input case, you should output:

            Case #X: Y
            where X is the number of the test case and Y is the last three integer digits of the number (3 + √5)n. In case that number has fewer than three integer digits, add leading zeros so that your output contains exactly three digits.

             

            Limits

            1 <= T <= 100

            Small dataset

            2 <= n <= 30

            Large dataset

            2 <= n <= 2000000000

            Sample

            Input 
             

            Output 
             
            2
            5
            2
            Case #1: 935
            Case #2: 027


            Analysis

            Solving the large tests was a very different problem. The difficulty comes from the fact that √5 is irrational and for n close to 2000000000 you would need a lot of precision and a lot of time if you wanted to use the naive solution.

            The key in solving the problem is a mathematical concept called conjugation. In our problem, we simply note that (3 - √5) is a nice conjugate for (3 + √5). Let us define

            (1)     α := 3 + √5,   β := 3 - √5,   and Xn := αn + βn.
            We first note that Xn is an integer. This can be proved by using the binomial expansion. If you write everything down you'll notice that the irrational terms of the sums cancel each other out.

            Another observation is that βn < 1, so Xn is actually the first integer greater than αn. Thus we may just focus on computing the last three digits of X.

            A side note. In fact, βn tends to 0 so quickly that that our problem would be trivial if we asked for the three digits after the decimal point. For all large values of n they are always 999.


            SO, the last three digits of Xn-1 is what we want. We also know that X(n)=6X(n-1)-4X(n-2),X(0)=2,X(1)=6,so we can calc Xn easily.

            code


            posted on 2009-08-28 09:13 baby-fly 閱讀(586) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm
            国产视频久久| 亚洲国产成人久久一区久久| 青青草原精品99久久精品66| 久久青草国产手机看片福利盒子| 久久久久国产视频电影| 久久久久无码精品国产不卡| 亚洲综合婷婷久久| 97久久国产综合精品女不卡| 伊人丁香狠狠色综合久久| 一本一本久久A久久综合精品| 成人免费网站久久久| 久久天天婷婷五月俺也去| 国产精品18久久久久久vr| 狠狠色丁香婷婷久久综合| 中文字幕亚洲综合久久| 亚洲国产精品无码久久| 久久久受www免费人成| 91精品国产综合久久香蕉| 久久精品亚洲中文字幕无码麻豆 | 无码人妻少妇久久中文字幕 | 久久这里都是精品| 人人狠狠综合久久亚洲婷婷| 久久久无码人妻精品无码| 国产精品久久久久久五月尺| 久久九色综合九色99伊人| www亚洲欲色成人久久精品| 久久国产免费观看精品| 亚洲AV无码1区2区久久| 777午夜精品久久av蜜臀| 久久婷婷午色综合夜啪| 久久天天婷婷五月俺也去| 久久亚洲精品无码观看不卡| 日韩久久无码免费毛片软件| 久久伊人影视| 久久综合偷偷噜噜噜色| 免费无码国产欧美久久18| 区久久AAA片69亚洲| 久久狠狠爱亚洲综合影院| 亚洲精品乱码久久久久久久久久久久| 亚洲国产一成久久精品国产成人综合| 亚洲&#228;v永久无码精品天堂久久 |