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

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(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
            • 評論內容較長,點擊標題查看
            • --王私江
            国产精品99久久99久久久| 久久性生大片免费观看性| 亚洲国产一成人久久精品 | 日韩精品久久无码中文字幕| 嫩草伊人久久精品少妇AV| 日本一区精品久久久久影院| 久久996热精品xxxx| 色99久久久久高潮综合影院| 久久综合亚洲鲁鲁五月天| 2021久久国自产拍精品| 亚洲国产精品嫩草影院久久| 国产精品久久久久影视不卡| 伊人久久大香线蕉成人| 国内精品久久久久久久久| 欧美与黑人午夜性猛交久久久| 久久久久人妻一区精品性色av| 99精品久久久久久久婷婷 | 91精品国产91久久久久久蜜臀| 亚洲欧美日韩精品久久亚洲区| 国产亚洲欧美成人久久片 | 久久影院亚洲一区| 久久久国产精品网站| 亚洲香蕉网久久综合影视 | 久久久久久午夜成人影院| 精品永久久福利一区二区| 性高朝久久久久久久久久| 久久99精品久久久久久秒播| 久久精品国产亚洲AV无码麻豆| 久久国产精品一区二区| 国产精品中文久久久久久久| 久久九九久精品国产免费直播| 久久精品天天中文字幕人妻| 久久夜色精品国产亚洲| 香蕉99久久国产综合精品宅男自 | 色综合久久88色综合天天 | 精品免费tv久久久久久久| 久久亚洲美女精品国产精品| 亚洲精品午夜国产VA久久成人| 三级三级久久三级久久| 午夜精品久久影院蜜桃| 亚洲欧美一区二区三区久久|