1732 Fibonacci Series 2

Source: Internet
Author: User

1732 Fibonacci Series 2

time limit: 1 sspace limit: 128000 KBtitle level: Diamonds Diamond SolvingTitle Description Description

In the "1250 Fibonacci series", we find the value of the nth Fibonacci series. But in 1250, n<=109. Now, your task is still to find the value of the nth Fibonacci sequence, but note that n is an integer and 1 <= n <= 100000000000000

Enter a description Input Description

Enter multiple sets of data, one row for each group of data, and an integer n (1 <= n <= 100000000000000)

Output description Output Description

Outputs several rows. Output per line (corresponding input) n Fibonacci number (considering the number will be very large, mod 1000000007)

Sample input Sample Input

3
4
5

Sample output Sample Output

2
3
5

Data range and Tips Data Size & Hint

1 <= N <= 100000000000000

Category labels Tags Click here to expandMatrix multiplication Number Theory AC Code:
#include <cstdio>#include<cstring>#include<iostream>using namespacestd;#definell Long LongConstll mod=1000000007; ll a[2][2],b[2][2],c[2][2];intMain () {ll n;  while(SCANF ("%lld", &n) = =1){        if(n==1) {puts ("1");Continue;} if(n==2) {puts ("1");Continue;} if(n==3) {puts ("2");Continue;} N-=3; a[0][0]=1; a[0][1]=1; a[1][0]=1; a[1][1]=0; b[0][0]=1; b[0][1]=1; b[1][0]=1; b[1][1]=0;  while(n) {if(n&1) {c[0][0]= (a[0][0]*b[0][0]%mod+a[0][1]*b[1][0]%MOD)%MoD; c[0][1]= (a[0][0]*b[0][1]%mod+a[0][1]*b[1][1]%MOD)%MoD; c[1][0]= (a[1][0]*b[0][0]%mod+a[1][1]*b[1][0]%MOD)%MoD; c[1][1]= (a[1][0]*b[0][1]%mod+a[1][1]*b[1][1]%MOD)%MoD; memcpy (A,c,sizeofc); } c[0][0]= (b[0][0]*b[0][0]%mod+b[0][1]*b[1][0]%MOD)%MoD; c[0][1]= (b[0][0]*b[0][1]%mod+b[0][1]*b[1][1]%MOD)%MoD; c[1][0]= (b[1][0]*b[0][0]%mod+b[1][1]*b[1][0]%MOD)%MoD; c[1][1]= (b[1][0]*b[0][1]%mod+b[1][1]*b[1][1]%MOD)%MoD; memcpy (B,c,sizeofc); N>>=1; } printf ("%lld\n", (a[0][0]+a[0][1])%MoD); }    return 0;}

1732 Fibonacci Series 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.