CodeChef Solution CHN08 - Crazy Malvika discovers Crazy Fibonacci function in C | Beginner
CodeChef Online Judge Solution CHN08 - Crazy Malvika discovers Crazy Fibonacci function| Beginner
CodeChef Main Problem Link -
Problem Name: CodeChef Problem CHN08 - Crazy Malvika discovers Crazy Fibonacci function
Problem Number : CodeChef Problem CHN08 - Crazy Malvika discovers Crazy Fibonacci function Solution
Online Judge : CodeChef Online Judge Solution
Level: Beginner
Code: CHN08
Solution Language : C
Learn Basic Of Fibonacci Algorithm:
CodeChef Solution CHN08 Code in C:
#include <stdio.h> int make_mod(int a, int b) { int r = a % b; return r < 0 ? r + b : r; } int fib(int a, int b, int x) { switch(x%6) { case 1: return a; case 2: return b; case 3: return b - a; case 4: return -a; case 5: return -b; case 0: return -b + a; } } int main() { int a,b,n,r,t,i; scanf("%d",&t); for(i=0; i < t; i++) { scanf("%d %d %d", &a, &b, &n); r = fib(a,b,n); printf("%d\n",make_mod(r, 1000000000+7)); } return 0; }
Learn More at devsenv - https://devsenv.com/codes/code-example-with-fibanoacci-numbers
ReplyDelete