• <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 閱讀(222) 評論(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
            • 評論內容較長,點擊標題查看
            • --王私江
            久久午夜无码鲁丝片| 日本WV一本一道久久香蕉| 欧美丰满熟妇BBB久久久| 嫩草伊人久久精品少妇AV| 精品精品国产自在久久高清| 麻豆精品久久久一区二区| 久久九九久精品国产| 亚洲精品国产字幕久久不卡| 伊人色综合久久| 天天躁日日躁狠狠久久| 欧美国产精品久久高清| 国产亚洲综合久久系列| 99久久免费国产精品特黄| 久久精品www| 久久精品国产亚洲AV嫖农村妇女| 欧美久久天天综合香蕉伊| 大伊人青草狠狠久久| 97精品依人久久久大香线蕉97| 日本免费久久久久久久网站| 狠狠精品久久久无码中文字幕| 精品国产综合区久久久久久| 久久精品无码专区免费青青| 国产精品久久久久久久久软件| 久久精品成人| 国产精品永久久久久久久久久| 精品久久久久久亚洲精品| 亚洲午夜久久久久久久久电影网| 欧美粉嫩小泬久久久久久久 | 久久99精品久久久久久hb无码| 热RE99久久精品国产66热| 一级做a爱片久久毛片| 国产精品美女久久久m| 久久超碰97人人做人人爱| 久久久国产乱子伦精品作者| 亚洲AV无码1区2区久久 | 26uuu久久五月天| 久久免费线看线看| 国产精品99久久久久久董美香| 久久久久久免费一区二区三区 | 久久久久久国产精品免费无码| 亚洲精品无码专区久久久|