Fellis Function Morris Fellis has come up with a new function called the Fellis…
- User
Fellis Function
Morris Fellis has come up with a new function called the Fellis Function. Morris defines the function as follows:
- f(0) = {1}
- f(1) = {1}
- f(N) = f(N - 1) + 7 + f(N - 2) + (N/4) modulo 10^7.
Given an integer N, your task is to help Morris find and return an integer value of f(N), after performing the Fellis Function.
Note: Here the division operator is an integer division operator i.e., it divides two numbers and returns the integer part of the result.
Input Specification:
- input1 : An integer value N representing the Fellis Function value.
Output Specification:
- Return an integer value of f(N), after performing the Fellis Function.
Example 1:
- input1 : 3 Output : 15
Explanation: Here in this example, we need to find the value of f(N). According to the question, f(0) = 1 and f(1) = 1.
Now, putting N = 2 in the Fellis Function, we get, f(2) = f(2-1) + 7 + f(2-2) + (2/4) modulo 10^9 + 7 f(2) = 8
Then, putting N = 3 in the Fellis Function we get, f(3) = (f(3-1) + 7 + f(3-2) + (3/4)) modulo 1000000007 f(3) = 15
Hence 15 is returned as the output.
Example 2: input1 : 1
Output : 1
Explanation: Here in this example, we need to find f(1). Fortunately, the value of f(1) = 1 modulo 1e^9 + 7 is already provided in the question.
Hence 1 is returned as the output. for the above problem give cpp answer in fom of following function : int fellisFunction(int input)
{
// Read only region end
// Write code here
throw "Function fellisFunction(int input) not implemented.";
} also split code into one other function - Assistant
#include<bits/stdc++.h> using namespace std; // Helper function to compute the Fellis Function int computeFellis(int N) { const int MOD = 1000000007; if(N == 0 || N == 1) { return 1; } long long a = 1; // f(N-2) long long b = 1; // f(N-1) long long c = 0; // f(N) for(int i = 2; i <= N; i++) { c = (b + 7 * a + (i / 4)) % MOD; a = b; b = c; } return (int)b; } // Main function to be implemented int fellisFunction(int input) { // Write code here return computeFellis(input); }