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, is the first Fibonacci number for which the last nine digits are 1-9 pandigital (contain all the digits 1 to 9, but not necessarily in order). And F2749, which contains 575 digits, is the first Fibonacci number for which the first nine digits are 1-9 pandigital.

Given that Fk is the first Fibonacci number for which the first nine digits AND the last nine digits are 1-9 pandigital, find k.


两端为全数字的斐波那契数

斐波那契数列由如下递归关系生成:

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

可以发现,包含有113位数字的F541是第一个后9位数字是1至9全数字(包含1至9所有的数字,但不一定按照从小到大的顺序)的斐波那契数,而包含有575位数字的F2749是第一个前9位数字是1至9全数字的斐波那契数。

若Fk是第一个前9位数字和后9位数字都是1至9全数字的斐波那契数,求k。

解题

直接暴力,可取,时间过长,没有那么多时间跑

mathblog 算了下4.6天,完全不能容忍的

想到直接根据公式计算,但是也不是很好的,Mathblog中提到了,只求fib的第九位,判断是否是0-9的数

利用 ,估算fib的值,或者说,当n很大的时候这个数和fib对于位的数是相等的,在题解中也看到好多都是根据这个思想计算的

其推到过程

Python
运行结果不对

不知道为什么

# coding=gbk

import time as time
import re
import math
import numpy as np
import math
def run():
f1 = 1
f2 = 1
index = 1
while True:
f = (f1 + f2)%1000000000
f1 = f2
f2 = f
index +=1
if isPandigital(f):
if first9(index):
print index
break def first9(n):
t = n *0.20898764024997873 - 0.3494850021680094
last9 = int(10**(t - int(t)+8 ))
return isPandigital(last9)
def isPandigital(s):
if len(str(s)) !=9:return False
return set(str(s)) == set('') t0 = time.time()
run()
t1 = time.time()
print "running time=",(t1-t0),"s"

Project Euler 104:Pandigital Fibonacci ends 两端为全数字的斐波那契数的更多相关文章

  1. HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)

    HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意:  求第n个斐波那契数的 ...

  2. [Swift]LeetCode509. 斐波那契数 | Fibonacci Number

    The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such th ...

  3. Python练习题 030:Project Euler 002:偶数斐波那契数之和

    本题来自 Project Euler 第2题:https://projecteuler.net/problem=2 # Each new term in the Fibonacci sequence ...

  4. HDU 1568 Fibonacci【求斐波那契数的前4位/递推式】

    Fibonacci Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Proble ...

  5. Colossal Fibonacci Numbers(巨大的斐波那契数)UVA 11582

    评测地址:http://acm.hust.edu.cn/vjudge/problem/41990 The i'th Fibonacci number f (i) is recursively de n ...

  6. UVA 11582 Colossal Fibonacci Numbers! 大斐波那契数

    大致题意:输入两个非负整数a,b和正整数n.计算f(a^b)%n.其中f[0]=f[1]=1, f[i+2]=f[i+1]+f[i]. 即计算大斐波那契数再取模. 一开始看到大斐波那契数,就想到了矩阵 ...

  7. 842. Split Array into Fibonacci Sequence能否把数列返回成斐波那契数列

    [抄题]: Given a string S of digits, such as S = "123456579", we can split it into a Fibonacc ...

  8. UVA - 11582 Colossal Fibonacci Numbers! (巨大的斐波那契数!)

    题意:输入两个非负整数a.b和正整数n(0<=a,b<264,1<=n<=1000),你的任务是计算f(ab)除以n的余数,f(0) = 0, f(1) = 1,且对于所有非负 ...

  9. (斐波那契总结)Write a method to generate the nth Fibonacci number (CC150 8.1)

    根据CC150的解决方式和Introduction to Java programming总结: 使用了两种方式,递归和迭代 CC150提供的代码比较简洁,不过某些细节需要分析. 现在直接运行代码,输 ...

随机推荐

  1. iOS另类的内存管理

    iOS的内存管理算是老生常谈的问题了,我们写iOS的时候无时无刻不在涉及到内存管理.从开始的MRR(manual retain-release)到后来ARC(Automatic Reference C ...

  2. mif_maker2010.exe下载和使用说明

    mif_malker2010.exe下载地址:http://pan.baidu.com/s/1bCqAp4 使用说明:http://www.cnblogs.com/BitArt/archive/201 ...

  3. [转] Matlab中给信号加高斯白噪声的方法

    MATLAB中产生高斯白噪声非常方便,可以直接应用两个函数,一个是WGN,另一个是AWGN.WGN用于产生高斯白噪声,AWGN则用于在某一信号中加入高斯白噪声. 1. WGN:产生高斯白噪声 y = ...

  4. 多线程 -- NSThread

    NSThread NSThread 一个NSThread对象就代表一条线程 创建线程的几种方式 alloc/init // 1.创建线程 NJThread *thread = [[NJThread a ...

  5. 带搜索框的下拉框chosen.jQury.js

    下载所需js,css png资源     <link href="chosen.css" rel="stylesheet" type="text ...

  6. dd面试经历

     HR面:看了我的简历,说fe做的简历就是不一样哈哈好吧,然后随便问了点项目,又问了什么时候可以去实习,就没了.三面:基本数据结构.冒泡排序.数组去重.ie与主流浏览器事件绑定.垂直居中的css实现方 ...

  7. 嵌入字体@font-face

    嵌入字体@font-face @font-face能够加载服务器端的字体文件,让浏览器端可以显示用户电脑里没有安装的字体. 语法: @font-face { font-family : 字体名称; s ...

  8. JavaScript DOM动态创建(声明)Object元素

    http://www.cnblogs.com/GuominQiu/archive/2011/04/01/2002783.html 一文提及“等整个页面加载完毕后,根据用户所选的阅读机类型,再用Java ...

  9. 服务端提供的JSON数据接口与用户端接收解析JSON数据

    JSON格式的服务接口:http://www.cnblogs.com/visec479/articles/4118338.html 首先来了解下JSON格式解析 json结构的格式就是若干个 键/值( ...

  10. schedule和scheduleAtFixedRate区别

    需求: 由于系统长期运作,各设备之间产生很多信息,一段时间后需要清除数据 考虑方案: 用schedule还是scheduleAtFixedRate,在此比较分析了下这两个的区别 schedule和sc ...