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

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 330187
            • 排名 - 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
            久久精品国产一区二区电影| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 久久精品国产男包| 97精品久久天干天天天按摩| 国产高潮久久免费观看| 久久精品国产2020| 久久久久久久综合日本| 久久久久亚洲AV无码专区体验| 亚洲国产精品久久| 国产成人精品久久| 女同久久| 国内精品免费久久影院| 国内精品伊人久久久久AV影院| 人妻无码精品久久亚瑟影视| 国产产无码乱码精品久久鸭| 色狠狠久久综合网| 久久婷婷五月综合成人D啪| 久久99热只有频精品8| 伊人久久大香线蕉精品不卡| 久久91这里精品国产2020| 久久精品成人免费看| 久久亚洲精品国产精品| 亚洲欧美成人综合久久久| 午夜精品久久久久成人| 青青草国产97免久久费观看| 麻豆精品久久久一区二区| 99久久99这里只有免费费精品| 久久国语露脸国产精品电影| 亚洲国产精品无码久久九九| 久久精品亚洲欧美日韩久久| 国产一区二区精品久久岳| 一级做a爱片久久毛片| 国内精品久久久久久久涩爱| 九九热久久免费视频| 久久久青草青青国产亚洲免观| 国内精品久久久久久不卡影院 | 囯产精品久久久久久久久蜜桃| 热99RE久久精品这里都是精品免费 | 久久国产精品99精品国产987| 国产精品99精品久久免费| 精品一区二区久久|