题意:

  求不大于4000000的斐波那契数列中,所有偶数之和.

SOL:

  还是只会暴模...看讨论区貌似有一个很牛逼的大神的发言?

  英语水平太差...

  mark以下

The Fibonacci sequence is a driven by the second order linear difference equation Fn+2 = Fn+1 + Fn, with boundary conditions F1 = 1, F2 = 1, and thus can be solved exactly. As we know from practice that Fn is roughly exponential, we try Fn = Aa^n for A and a constants. This gives the quadratic a^2 = a + 1, which happens to be the equation for the golden ratio Φ, and its inverse which I'll denote Φ' (i.e. Φ' = 1/Φ, Φ' = Φ - 1) As the equation is second order then it is a linear combination of these two solutions and the boundary conditions define the constants involved, i.e. Fn = AΦ^n + BΦ'^n F0 = 0 (easy if you follow backwards) so A + B = 0 F1 = 1 . Using Φ = (1 + r)/2 and Φ' = (1 - r)/2 where r is the positive square root of 5, you can find A - B = 2/r yielding A = 1/r, B = -1/r So Fn = (Φ^n /r) - (Φ'^n /r) = (Φ^n - Φ'^n)/r for all n. As can be seen, the even terms are when n is a multiple of 3, so using this formula add F3 + F6 + ... until you get a term greater than one million. Thus a program for this could be only a handful of lines long. A slightly further simplification would be to work out Φ^3 and Φ'^3, call them b and b' respectively. Then F3k = (b^k - b'^k)/r for k = 1,2,3...

PE-2 & 暴模...的更多相关文章

  1. PE-1 & 暴模|容斥

    题意: 求1000以下3或5的倍数之和. SOL: 暴模也是兹瓷的啊... 那么就想到了初赛悲催的滚粗...容斥忘了加上多减的数了... 然后对着题...T = 3*333*(1+333)/2 + 5 ...

  2. PE的一些水 3-50

    T3: 分解质因数. lalala T4: 暴模. 然而数学方法怎么搞?---->也就是怎么手算?... 于是看了一下讨论区...发现原来我的数学已经低于小学生水平了... 我们把答案abccb ...

  3. 【旧文章搬运】暴搜内存查找PE镜像

    原文发表于百度空间,2008-7-28========================================================================== 前面介绍了修 ...

  4. hiho一下 第九十七周 数论六·模线性方程组

    题目1 : 数论六·模线性方程组 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:今天我听到一个挺有意思的故事! 小Hi:什么故事啊? 小Ho:说秦末,刘邦的将军 ...

  5. PE结构详解

    1 基本概念 下表描述了贯穿于本文中的一些概念: 名称 描述 地址 是“虚拟地址”而不是“物理地址”.为什么不是“物理地址”呢?因为数据在内存的位置经常在变,这样可以节省内存开支.避开错误的内存位置等 ...

  6. HDU - 6185 Covering(暴搜+递推+矩阵快速幂)

    Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...

  7. NOIP2018提高组省一冲奖班模测训练(一)

    比赛链接 https://www.51nod.com/contest/problemList.html#!contestId=72&randomCode=147206 这次考试的题非常有质量 ...

  8. POJ 3188暴搜

    题意: 思路: 裸的暴搜 --. 但是要注意如果你不用所有的按键就能输出最优解的话一定要把所有的字母都安排到一个位置-. 我的一群PE就是这么来的-- 为什么写的人这么少-- // by Sirius ...

  9. HDU 4704 Sum 超大数幂取模

    很容易得出答案就是2^(n-1) 但是N暴大,所以不可以直接用幂取模,因为除法操作至少O(len)了,总时间会达到O(len*log(N)) 显然爆的一塌糊涂 套用FZU1759的模板+顺手写一个大数 ...

随机推荐

  1. NYOJ题目74小学生算术

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsYAAAI0CAIAAACRUHjwAAAgAElEQVR4nO3dO3LbyroG0DsJ5RqIYg

  2. Javascript和Java获取各种form表单信息的简单实例

    大家都知道我们在提交form的时候用了多种input表单.可是不是每一种input表单都是很简单的用Document.getElementById的方式就可以获取到的.有一些组合的form类似于che ...

  3. mysqli扩展库的预处理技术 mysqli stmt

    //预编译演示 //1,创建mysqli对象 $mysqli=new mysqli("localhost","root",""," ...

  4. C#委托(Action、Func、predicate)

    Predicate 泛型委托:表示定义一组条件并确定指定对象是否符合这些条件的方法.此委托由 Array 和 List 类的几种方法使用,用于在集合中搜索元素. public delegate boo ...

  5. 动态生成SQL执行语句

    SET @qry = 'SELECT product_cd, name, product_type_cd, date_offered, date_retired FROM product WHERE ...

  6. python-logging-日志系统

    有时候需要记录日志,典型的出现在web程序或者服务器中,需要与正在运行的程序交互或者得知里面正在运行的信息 最近在倒腾webservice,使用spyne模块进行打包服务,很多实例代码也都用到了这个l ...

  7. 智能车学习(十七)——舵机学习

    一.舵机的结构      舵机简单的说就是集成了直流电机.电机控制器和减速器等,并封装在一个便于安装的外壳里的伺服单元.能够利用简单的输入信号比较精确的转动给定角度的电机系统.舵机安装了一个电位器(或 ...

  8. 自己yy的fulkson最大流算法

    #include <iostream> #include <cstdio> #include <vector> using namespace std; ; //m ...

  9. Js图片切换

    <!DOCTYPE html><html<head> <meta charset="UTF-8"> <title></t ...

  10. MySql数据库安装&修改密码&开启远程连接图解

    相关工具下载地址: mysql5.6 链接:http://pan.baidu.com/s/1o8ybn4I密码:aim1 SQLyog-12.0.8 链接:http://pan.baidu.com/s ...