Logu P1306 Fibonacci common count, p1306 Fibonacci

Source: Internet
Author: User

Logu P1306 Fibonacci common count, p1306 Fibonacci
Description

You should be familiar with the series of Fibonacci:, 13 ~~~ But now there is a very simple question: what is the maximum number of public appointments between the n and m items?

Input/Output Format

Input Format:

 

Two positive integers n and m. (N, m <= 10 ^ 9)

Note: The data is large.

 

Output Format:

 

The maximum number of common Fn and Fm.

Since reading big numbers makes you dizzy, you only need to output the last 8 digits.

 

Input and Output sample input sample #1: Copy
4 7
Output example #1: Copy
1
Description

Recursion and recurrence will time out.

The formula also times out.

 

 

 

Extended Euclidean has a very important nature

$ Gcd (F [I], F [j]) = F [gcd (I, j)] $

 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #define LL long long  5 using namespace std; 6 const LL mod=100000000; 7 const LL MAXN=5000001; 8 inline LL read() 9 {10     char c=getchar();LL x=0,flag=1;11     while(c<'0'||c>'9')    {if(c=='-')    flag=-1;c=getchar();}12     while(c>='0'&&c<='9')    x=x*10+c-48,c=getchar();return x*flag;13 }14 LL dp[MAXN];15 LL gcd(LL a,LL b)16 {17     return b==0?a:gcd(b,a%b);18 }19 int main()20 {21     LL n=read(),m=read();22     dp[1]=1;dp[2]=1;23     for(LL i=3;i<=5000000;i++)24         dp[i]=(dp[i-1]+dp[i-2])%100000000;25         26     LL p=gcd(n,m);27     printf("%lld",dp[p]%100000000);28     return 0;29 }

 

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.