The GCD of Fibonacci Numbers
程序员文章站
2022-06-07 22:03:42
...
#include <stdio.h>
#include <iostream>
using namespace std;
int gcd(long long a,long long b)
{
if(b==0)
{
return a;
}
else
{
return gcd(b,a%b);
}
}
int main()
{
int fib[50];
fib[0]=0;
fib[1]=1;
for(int i=2;i<=45;i++)
{
fib[i]=fib[i-1]+fib[i-2];
}
int n;
cin >> n;
long long a;
long long b;
while(n--)
{
cin >> a >> b;
int c=gcd(a,b);
cout << fib[c] << endl;
}
}