Project Euler 104:pandigital Fibonacci ends both ends of the full number Fibonacci number

Source: Internet
Author: User

Pandigital Fibonacci Ends

The Fibonacci sequence is defined by the recurrence relation:

F[n] = f[n-1] + f[n-2], where f[1] = 1 and f[2] = 1.

It turns out that F541, which contains 113 digits, was the first Fibonacci number for which the last nine digits was 1-9 PA Ndigital (contain all the digits 1 to 9, and not necessarily in order). And F2749, which contains 575 digits, is the first Fibonacci number for which the first nine digits is 1-9 pandigital.

Given that Fk was the first Fibonacci number for which the first nine digits and the last nine digits was 1-9 Pandigital, F IND K.

Fibonacci numbers with full numbers at both ends

The Fibonacci sequence is generated by the following recursive relationships:

F[n] = f[n-1] + f[n-2], where f[1] = 1 and f[2] = 1.

It can be found that the F541 with a 113-digit number is the first 9 digits 1 to 9 full digits (including 1 to 9 of all numbers, but not necessarily in the order of small to large), while the F2749 containing 575-digit numbers is the first 9-digit Fibonacci number with 1 to 9 full numbers.

If FK is the first 9 digits and the last 9 digits are 1 to 9 full-digit Fibonacci numbers, ask for K.

Solving

Direct violence, desirability, time too long, not so much time to run

Mathblog, 4.6 days, totally intolerable.

It is not very good to think of it directly on the basis of the formula, but the nineth bit of fib, Mathblog, is the number of 0-9.

Using, estimating the value of the fib, or, when n is very large, this number and fib are equal to the number of bits, and many of them are calculated according to this idea.

It pushes to the process

Python
Incorrect operation result

Don't know why

#CODING=GBKImport time as timeImportReImportMathImportNumPy as NPImportMathdefrun (): F1= 1F2= 1Index= 1 whiletrue:f= (F1 + F2)%1000000000F1=F2 F2=F Index+=1ifispandigital (f):ifFirst9 (index):PrintIndex Breakdeffirst9 (n): t= N *0.20898764024997873-0.3494850021680094Last9= Int (10** (t-int (t) +8 ))    returnispandigital (LAST9)defIspandigital (s):ifLen (str))!=9:returnFalsereturnSet (str (s)) = = Set ('123456789') T0=Time.time () run () T1=time.time ()Print "running Time=", (T1-T0),"s"            

Project Euler 104:pandigital Fibonacci ends both ends of the full number Fibonacci number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.