• <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>

            為生存而奔跑

               :: 首頁 :: 聯系 :: 聚合  :: 管理
              271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

            留言簿(5)

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 328427
            • 排名 - 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 閱讀(577) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm
            无码人妻久久一区二区三区免费丨 | 日日狠狠久久偷偷色综合96蜜桃| 久久夜色精品国产亚洲| 国产福利电影一区二区三区久久老子无码午夜伦不 | 精品久久久久久无码中文字幕一区| 久久超碰97人人做人人爱| 青青草原综合久久大伊人精品| 久久久久亚洲爆乳少妇无| 日韩精品久久无码人妻中文字幕| 久久综合丝袜日本网| 国产精品久久久久久五月尺| 69久久夜色精品国产69 | 性做久久久久久久| 亚洲国产成人久久精品动漫| 一级A毛片免费观看久久精品| 高清免费久久午夜精品| 婷婷伊人久久大香线蕉AV | 久久久久人妻一区二区三区vr| 久久精品国产69国产精品亚洲| 午夜视频久久久久一区| 久久无码人妻一区二区三区| 久久人人爽人人澡人人高潮AV| 国产∨亚洲V天堂无码久久久| 亚洲欧美国产日韩综合久久| 久久99国产亚洲高清观看首页| 综合久久一区二区三区 | 色综合久久88色综合天天 | 91精品国产91久久久久福利| 久久人做人爽一区二区三区| 久久国产三级无码一区二区| 情人伊人久久综合亚洲| 2022年国产精品久久久久 | 久久久精品国产Sm最大网站| 久久综合狠狠色综合伊人| 国产午夜免费高清久久影院| 久久夜色精品国产噜噜亚洲AV| 久久婷婷色综合一区二区| 久久综合久久美利坚合众国| 国内精品久久久久影院亚洲| 婷婷久久五月天| 麻豆av久久av盛宴av|