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

            poj3070

            Fibonacci

            Time Limit: 1000MS Memory Limit: 65536K
            Total Submissions: 6131 Accepted: 4296

            Description

            In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are:

            0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …

            An alternative formula for the Fibonacci sequence is

            .

            Given an integer n, your goal is to compute the last 4 digits of Fn.

            Input

            The input test file will contain multiple test cases. Each test case consists of a single line containing n (where 0 ≤ n ≤ 1,000,000,000). The end-of-file is denoted by a single line containing the number −1.

            Output

            For each test case, print the last four digits of Fn. If the last four digits of Fn are all zeros, print ‘0’; otherwise, omit any leading zeros (i.e., print Fn mod 10000).

            Sample Input

            0
            9
            999999999
            1000000000
            -1

            Sample Output

            0
            34
            626
            6875

            Hint

            As a reminder, matrix multiplication is associative, and the product of two 2 × 2 matrices is given by

            .

            Also, note that raising any 2 × 2 matrix to the 0th power gives the identity matrix:

            .

            Source


            呃,矩陣乘法快速冪嘛

            很好寫
            1A
            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            using namespace std;

            struct node
            {
                
            int a,b,c,d;
            }
            ;
            int n;
            node mul(node t1,node t2)
            {
                node tmp;
                tmp.a
            =t1.a*t2.a+t1.b*t2.c;
                tmp.b
            =t1.a*t2.b+t1.b*t2.d;
                tmp.c
            =t1.a*t2.c+t1.c*t2.d;
                tmp.d
            =t1.b*t2.c+t1.d*t2.d;
                tmp.a
            =tmp.a%10000;
                tmp.b
            =tmp.b%10000;
                tmp.c
            =tmp.c%10000;
                tmp.d
            =tmp.d%10000;
                
            return tmp;
            }

            node 
            get(node a1,int k)
            {
                node tmp;
                
            if(k==1)
                
            {
                    
            return a1;
                }

                
            else if(k==2return mul(a1,a1);
                
            else
                
            {
                    tmp
            =get(a1,k/2);
                    
            if(k&1)
                        
            return mul(mul(tmp,tmp),a1);
                    
            else return mul(tmp,tmp);
                }

            }

            int main()
            {
                node ans,a;
                a.a
            =1;
                a.b
            =1;
                a.c
            =1;
                a.d
            =0;
                
            while(scanf("%d",&n)!=EOF&&n!=-1)
                
            {
                    
            if(n==0)
                    
            {
                        printf(
            "0\n");
                        
            continue;
                    }

                    ans
            =get(a,n-1);
                    printf(
            "%d\n",ans.a);
                }

                
            return 0;
            }

            posted on 2012-07-20 23:16 jh818012 閱讀(223) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統(tǒng)計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內(nèi)容較長,點擊標題查看
            • --王私江
            亚洲人AV永久一区二区三区久久| 久久精品国产亚洲av麻豆图片| 久久综合狠狠综合久久| 人妻久久久一区二区三区| 国产成人精品白浆久久69| 国产精品99久久精品爆乳| 四虎亚洲国产成人久久精品| 久久精品一本到99热免费| 久久久无码精品午夜| 伊人久久综合成人网| 99久久婷婷国产综合精品草原| 伊人色综合九久久天天蜜桃| 日韩精品久久久久久久电影蜜臀| 四虎国产精品免费久久5151| 久久午夜无码鲁丝片秋霞| 日本久久久久久中文字幕| 久久久久av无码免费网| 国产高潮久久免费观看| 狠狠色噜噜色狠狠狠综合久久| 狠狠色综合久久久久尤物| 伊人久久综合成人网| 国产精品乱码久久久久久软件| 久久久久国产一级毛片高清版| 麻豆av久久av盛宴av| 精品国产乱码久久久久久浪潮| 国产精品久久国产精麻豆99网站 | 欧美精品福利视频一区二区三区久久久精品 | 久久综合九色综合欧美狠狠| 亚洲国产精品高清久久久| 久久综合久久伊人| 久久最新免费视频| 亚洲国产成人乱码精品女人久久久不卡 | 国产精品成人久久久| 蜜臀久久99精品久久久久久| 久久99精品九九九久久婷婷| 久久99热只有频精品8| 欧美日韩精品久久久免费观看 | AA级片免费看视频久久| 亚洲综合婷婷久久| 久久精品国产99久久丝袜| 欧美亚洲日本久久精品|