SDNUOJ 1683.easy problem Ⅳ

Description

定义斐波那契数列,F(1) = F(2) = 1,对于所有的N,满足F(N+2)=F(N+1)+F(N),求F(m)与F(n)的最大公约数
多组测试样例

Input

多组输入,每组两个整数,n, m(1 <= n <= 1000, 1 <= m <= 1000)

Output

F(m)与F(n)的最大公约数,结果不超过263-1

Sample Input

1 2

Sample Output

1

水题,斐波那契数列性质,注意开long long。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <cctype>
using namespace std;

typedef long long ll;
const ll mod = 1e9+7;

ll fib[100];

ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a%b);
}

int main()
{
    fib[1] = fib[2] = 1;
    for(int i = 3; i <= 100; ++i)
        fib[i] = fib[i-1] + fib[i-2];
    ll n, m;
    while(cin >> n >> m)
        cout << fib[gcd(n, m)] << '\n';
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值