Statistics

Problem Statement for "SuperFib"

Problem Statement

PROBLEM STATEMENT

We all know what the Fibonacci sequence is: a series such that the ith term is
the sum of the previous two terms, starting with 0,1.  Thus the sequence starts
0,1,1,2,3,5,8,13,21...  Each number is the sum of the preceding two.  But the
Fibonacci sequnce is old, its had its day and now its time for bigger and
better things.  You, being an astute observer of current trends and fahsion,
have noticed that the Fibonacci sequence, while once all the rave, is no longer
spoken of at happening events.

However, you feel that sequences in themselves are far from dead, and, because
you lust after notoriety and glory, you have decided that the next big sequence
to hit the scene should be named after you.  You decide that your sequence
should be reminiscent of the Fibonacci sequence because it seemed to have a
good formula for success, but also unique enough that it will not receive the
same lackadaisical response.

Thus, after many sleepless nights you come up with a brilliant idea.  Your
sequence will be like the Fibonacci sequence, except that each number will be
the sum of the previous three numbers, not the previous two.  However, you soon
realize that the initial three numbers make the sequence and that if those are
dull, the sequence will flop.  Thus, you write a computer program to help you
figure out which initial three numbers you should choose.

Create a class SuperFib that contains a method compute, which takes as input
four integers.  The first three are the first three terms of the sequence (in
order).  The fourth input, N, is the length to which your sequence should be
calculated.  Your method should return the sum of the first N terms in the
sequence.

DEFINITION
Class: SuperFib
Parameters: int, int, int, int
Returns: int
Method signature (be sure your method is public):  int compute(int a, int b,
int c, int N);

TopCoder will ensure the validity of the inputs.  Inputs are valid if all of
the following criteria are met:
- N is between 1 and 10000, inclusive 
- a, b, and c are all between -10000 and 10000, inclusive
- For all i less than N, the absolute value of the ith term and the absolute
value of the sum of all terms from 1 to i will be less than 2^15 = 32768

EXAMPLES
{0,0,1,7}
The sequence starts with (0,0,1) and the first 7 terms are as follows:
0,0,1,1,2,4,7
Each term is the sum of the previous 3.
The sum of all these is 15, so the method should return 15.

{1,2,3,8}
The series is:
1,2,3,6,11,20,37,68
The sum of this is: 148

{1,0,0,10}
returns 53

Definition

Class:
SuperFib
Method:
compute
Parameters:
int, int, int, int
Returns:
int
Method signature:
int compute(int param0, int param1, int param2, int param3)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: