• <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
            • 評論內容較長,點擊標題查看
            • --王私江
            久久一本综合| 久久超碰97人人做人人爱| 久久精品国产精品亚洲人人| 蜜桃麻豆www久久国产精品| 久久99九九国产免费看小说| 久久免费的精品国产V∧ | 久久中文精品无码中文字幕| 欧美久久天天综合香蕉伊| 中文字幕人妻色偷偷久久| 国产成人香蕉久久久久| 无码超乳爆乳中文字幕久久| 久久99久久成人免费播放| 久久天堂AV综合合色蜜桃网| 亚洲а∨天堂久久精品9966| 精品综合久久久久久97超人 | 天天躁日日躁狠狠久久| 久久高潮一级毛片免费| 国产成人久久精品激情| 亚洲а∨天堂久久精品9966| 伊人久久精品线影院| 色88久久久久高潮综合影院| 久久综合五月丁香久久激情| 国内精品久久久久| 亚洲av伊人久久综合密臀性色| 9999国产精品欧美久久久久久| 亚洲欧美伊人久久综合一区二区| 久久精品国产亚洲7777| 久久精品这里热有精品| 无码人妻精品一区二区三区久久 | 久久人人爽人爽人人爽av| 日本精品久久久久中文字幕8| 久久精品国产亚洲AV无码偷窥 | 久久99国产综合精品免费| 久久久SS麻豆欧美国产日韩| 亚洲成av人片不卡无码久久| 亚洲Av无码国产情品久久| 久久久久国产视频电影| 亚洲精品tv久久久久久久久久| 色偷偷91久久综合噜噜噜噜| 欧美国产成人久久精品| 无码人妻久久一区二区三区蜜桃|