TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

FibonacciSequence

Problem statement, definition, constraints, and public examples.

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

  1. 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}.
  2. 12
    13
    Returns: 1
  3. 13
    13
    Returns: 1
Back to all problems