You are not logged in. Please login at www.codechef.com to post your questions!

×

fibonacci modified

https://www.hackerrank.com/challenges/fibonacci-modified/problem

i found this question on hackerrank. can anyone explain how this can be solved using c++ .

asked 26 Oct '18, 05:44

sumesh_pandit's gravatar image

3★sumesh_pandit
0
accept rate: 0%


@sumesh --

The basics of the solution is a simple loop. This is pseudocode...

    declare t_Nminus2 := t1  // function parameter
    declare t_Nminus1 := t2  // function parameter
    declare t_N

    for i := 3 to n inclusive  // n is a function parameter
        t_N := t_Nminus2 + t_Nminus1 * t_Nminus1
        t_Nminus2 := t_Nminus1
        t_Nminus1 := t_N
    end for

    return t_N

The challenge isn't the base algorithm outlined above. The challenge is the datatype to use for t_N.

Since n can be up to 20 and the next term includes the square of the prior term, the max possible value of t_N is much larger than ULLONG_MAX (largest possible unsigned long long int), as the HackerRank problem statement says. There is no native data type in C++ that can handle such large integers, so it's possible this problem wants you to create your own datatype.

link

answered 27 Oct '18, 23:11

sbatten1969's gravatar image

3★sbatten1969
583
accept rate: 16%

edited 27 Oct '18, 23:12

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,559
×2,093
×3

question asked: 26 Oct '18, 05:44

question was seen: 108 times

last updated: 27 Oct '18, 23:12