Interview Questions: The rules for one column are as follows:: 1,1,2,3,5,8,13,21,34 ......Find30What is the number of digits, RecursionAlgorithmImplementation (C #).
After I got out of a software company that has been working for more than four years (wangxin software), I have been interviewing these days, but I have not found a suitable one. Seeing these basic interview questions is a little difficult to do. I haven't been reading these basic questions for a long time. It's a little unfamiliar.
From the rule of the series, we can see that, starting from the third digit, the value is equal to the sum of the first two numbers30The number of digits.28Bitwise AND29The sum of BITs, and29The number of digits is27Bitwise AND28The sum of digits. At that time, according to this idea, the code was not implemented on the exam.
When I go home, I search online. Most of the answers are similar:
Class Program
{
Static VoidMain (String[] ARGs)
{
Console.Writeline (String.Format ("{0 }", Foo (50)));
Console.Read ();
}
Public Static LongFoo (IntI)
{
LongResult= 0;
If(I<= 0)
Return 0;
Else If(I> 0 &&I<= 2)
Return 1;
Else
Result=Foo (I- 1)+Foo (I- 2);
// Console. Write (string. Format ("{0} \ t", result ));
ReturnResult;
}
}
SuchProgramExtremely low performance, display50The result is basically not displayed, and developers are completely misled. To this end, I will implement my ideas as programs, programsCodeAs follows:
Class Program
{
Static VoidMain (String[] ARGs)
{
Console.Writeline (String.Format ("{0 }", Getresult (91)));
Console.Read ();
}
Public Static LongGetresult (IntNumber)
{
If(Number<= 2)
Return 1;
ReturnGetresult (1,1,3, Number );
}
Private Static LongGetresult (LongLeft,LongRight,IntCount,IntNumber)
{
LongResult=Left+Right;
Console.Write (String.Format ("{0} \ t", Result ));
//Obtain the number of instances.
If(Count<Number)
{
Count=Count+ 1;
//Data transfer
Left=Right;
Right=Result;
//Recursive call
Result=Getresult (left, right, count, number );
}
ReturnResult;
}
}
For data and machine reasons, we can see the 91st-bit computing result, and the subsequent display is not normal. Is there any better way to calculate more digits? Thank you!
Correction is not recommended!