Under construction

Still being built. Things may change

Fibonacci Number Analysis

Time limit1sMemory limit128 MB

Summary
For each lo-hi range in hexadecimal, print every Fibonacci number inside it with its index, base-2 log, and prime factorization.
Level

Medium6 of 10

Topics
Math, Implementation, Number theory, Simulation
Solved
No attempts yet

Problem

The Fibonacci numbers F(n) are defined recursively as follows.

F(0)=0,F(1)=1,F(n)=F(n−1)+F(n−2) (n≥2)F(0) = 0, \quad F(1) = 1, \quad F(n) = F(n-1) + F(n-2) \ (n \ge 2)

Given an integer range [lo, hi], find every Fibonacci number that lies within the range (endpoints included) and, for each one, print the following information.

  • The index n and the value F(n)
  • Its base-2 logarithm lg, rounded to six decimal places
  • Its prime factorization in ascending order, with each repeated prime printed as many times as it occurs

The following rules apply.

  • 0 is the first Fibonacci number, but the logarithm of 0 is undefined, so print lg does not exist instead of a logarithm.
  • 0 and 1 have no prime factors, so print No prime factors instead of a factorization.
  • If the range contains no Fibonacci number, print No Fibonacci numbers in the range.

Fibonacci numbers with different indices but equal values, such as F(1) = 1 and F(2) = 1, are printed separately.

Input

The input consists of several ranges. Each range is given on its own line as two non-negative integers lo and hi. Both numbers are written in hexadecimal with a 0x prefix; for example, 0x1a denotes 26.

Every integer fits in the signed 64-bit range. Input ends at end of file (EOF), or at the first line where lo ≥ hi. (The line that meets the termination condition is not processed.)

Output

For each processed range, first print the header Range {lo} to {hi}: using the decimal values. Then, for each Fibonacci number in the range, print two lines in the following format.

  • First line: Fib({n}) = {value}, lg is {log} (if the value is 0, print Fib({n}) = 0, lg does not exist)
  • Second line: Prime factors: {factors} (if the value is 0 or 1, print No prime factors)

The base-2 logarithm (lg) is printed to six decimal places, and prime factors are separated by single spaces. Separate the output of different ranges with a single blank line.

Examples3

  1. Example 1

    Input
    0x0 0x8
    0x9 0xc
    0x9 0x40
    0x0 0x0
    
    Expected output
    Range 0 to 8:
    Fib(0) = 0, lg does not exist
    No prime factors
    Fib(1) = 1, lg is 0.000000
    No prime factors
    Fib(2) = 1, lg is 0.000000
    No prime factors
    Fib(3) = 2, lg is 1.000000
    Prime factors: 2
    Fib(4) = 3, lg is 1.584963
    Prime factors: 3
    Fib(5) = 5, lg is 2.321928
    Prime factors: 5
    Fib(6) = 8, lg is 3.000000
    Prime factors: 2 2 2
    
    Range 9 to 12:
    No Fibonacci numbers in the range
    
    Range 9 to 64:
    Fib(7) = 13, lg is 3.700440
    Prime factors: 13
    Fib(8) = 21, lg is 4.392317
    Prime factors: 3 7
    Fib(9) = 34, lg is 5.087463
    Prime factors: 2 17
    Fib(10) = 55, lg is 5.781360
    Prime factors: 5 11
  2. Example 2

    Input
    0x1 0x4
    0x0 0x0
    
    Expected output
    Range 1 to 4:
    Fib(1) = 1, lg is 0.000000
    No prime factors
    Fib(2) = 1, lg is 0.000000
    No prime factors
    Fib(3) = 2, lg is 1.000000
    Prime factors: 2
    Fib(4) = 3, lg is 1.584963
    Prime factors: 3
  3. Example 3

    Input
    0xa 0xd
    0x0 0x0
    
    Expected output
    Range 10 to 13:
    Fib(7) = 13, lg is 3.700440
    Prime factors: 13