## Problem

After a long time in-door researched, Hung found a good approach to attract a girl and he named it *“Girl attracting law by Fibonacci approach”* that means the number of presents Hung gives to her is increased by Fibonacci sequence. But don’t stop, he extended to version 2 with some customisation by:

**T(n+2) = T(n+1) * T(n+1) + T(n)**

with **T(n)** is a number of presents at the n*th* dating.

Hung of course has a lot of money but wants to trust a girl, so he should give her 0 present at the first and 1 present at the second dating. And following his theory, 5 presents should be given in the 5th dating as explanation below:

1^{st} number = 0

2^{nd} number = 1

3^{rd} number = 1^{2} + 0 = 1

4^{th} number = 1^{2} + 1 = 2

^{5th} number = 2^{2} + 1 = 5

Hung said that he has meet her 13 times and today he wants to know how many present he should give. Could you help Hung?

## Solution

It seems very easy because the Fibonacci is a basic problem we usually do in learning programming. But, please aware that the number in this sequence increase too fast and need a wide range of positive number. In C# or Java, you could use BigInteger type.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
using System; using System.Numerics; namespace CodeChallengeSolution.Challenge_1 { public class GirlAttracion { public static void Main( string[] args ) { BigInteger a = 0; BigInteger b = 1; for ( int i = 2; i < 14; i++ ) { BigInteger c = BigInteger.Pow( b, 2 ) + a; a = b; b = c; } Console.WriteLine( b ); } } } |

1,165 total views, 1 views today