TopCoder problem "FibonacciSequence" used in TCHS SRM 22 (Division I Level One)



Problem Statement

    A fibonacci sequence is defined recursively as follows:

  • F1 = F2 = 1;
  • Fn = Fn-1 + Fn-2;
Given two integers a and b, return the number of fibonacci numbers between a and b, inclusive.

 

Definition

    
Class:FibonacciSequence
Method:numFibs
Parameters:int, int
Returns:int
Method signature:int numFibs(int a, int b)
(be sure your method is public)
    
 

Constraints

-a will be between 2 and 1000, inclusive.
-b will be between a and 1000, inclusive.
 

Examples

0)
    
2
5
Returns: 3
The fibonacci sequence is {1,1,2,3,5,...}. There are 3 fibonacci numbers between 2 and 5, inclusive: {2,3,5}.
1)
    
12
13
Returns: 1
2)
    
13
13
Returns: 1

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7262

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10074&pm=7262

Writer:

myprasanna

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Brute Force, Recursion