Dev Skill The Last Fibonacci

 ?? Detail: Program to find last digit of n’th Fibonnaci Number

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define sf scanf
#define pf printf

LL f[65] = {0};

LL fib(LL n)
{
    f[0] = 0;
    f[1] = 1;

    for (LL i = 2; i <= n; i++)
    {
        f[i] = (f[i-1] + f[i-2])%10;
    }

    return f[n];
}

LL findLastDigit(LL n)
{
    fib(60);

    return f[n%60];
}

int main()
{
    int t , tc=0;
    LL n;
    sf("%d", &t);
    while(t--)
    {
        memset(f , 0 , sizeof f);

        sf("%lld", &n);

        pf("Case %d: %lld is the last digit.\n", ++tc, findLastDigit(n));
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number