Project Euler 25 1000-digit Fibonacci number
题意:在斐波那契数列( 1 ,1,2,3,5 ...... )中,第一个有1000位数字的是第几项?
思路:****滚动数组 + 大数加法
/*************************************************************************
> File Name: euler025.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月25日 星期日 11时24分33秒
************************************************************************/
#include <stdio.h>
#include <inttypes.h>
int32_t main() {
int32_t fib[3][1100] = {0}; // fib[][0] 记录该数组所代表数字的最大位数
fib[1][0] = fib[1][1] = 1;
fib[2][0] = fib[2][1] = 1;
int32_t number = 2 , idx1 , idx2 , idx3;
while( fib[ number % 3 ][0] < 1000 ) {
number++;
idx1 = (number - 2) % 3; // 依靠取模运算进行“滚动”,fib[idx1] < fib[idx2] < fib[idx3]
idx2 = (number - 1) % 3;
idx3 = number % 3;
for(int32_t i = 1 ; i <= fib[idx2][0] ; i++)
fib[idx3][i] = fib[idx2][i] + fib[idx1][i];
fib[idx3][0] = fib[idx2][0];
for(int32_t i = 1 ; i <= fib[idx3][0] ; i++) {
if( fib[idx3][i] >= 10 ){
fib[idx3][i+1] += fib[idx3][i] / 10;
fib[idx3][i] %= 10;
if( fib[idx3][0] < i + 1 ) fib[idx3][0] = i + 1;
}
}
}
printf("%d\n",number);
return 0;
}
Project Euler 25 1000-digit Fibonacci number的更多相关文章
- project euler 25 fibonacci
数学方法: Saying that a number contains 1000 digits is the same as saying that it's greater than 10**999 ...
- project euler 12 Highly divisible triangular number
Highly divisible triangular number Problem 12 The sequence of triangle numbers is generated by addin ...
- Project Euler 92:Square digit chains C++
A number chain is created by continuously adding the square of the digits in a number to form a new ...
- Project Euler 20 Factorial digit sum( 大数乘法 )
题意:求出100!的各位数字和. /************************************************************************* > Fil ...
- Project Euler 16 Power digit sum( 大数乘法 )
题意: 215 = 32768,而32768的各位数字之和是 3 + 2 + 7 + 6 + 8 = 26. 21000的各位数字之和是多少? 思路:大数乘法,计算 210 × 100 可加速计算,每 ...
- Project Euler 435 Polynomials of Fibonacci numbers (矩阵快速幂)
题目链接: https://projecteuler.net/problem=435 题意: The Fibonacci numbers $ {f_n, n ≥ 0}$ are defined rec ...
- Project Euler 51: Prime digit replacements
通过替换*3这样一个两位数的第一位,我们可以发现形成的九个数字有六个是质数,即13, 23,43,53,73,83.类似的,如果我们用同样的数字替换56**3这样一个五位数的第三位和第四位,会生成56 ...
- Project Euler 56: Powerful digit sum
一个古戈尔也就是\(10^{100}\)是一个天文数字,一后面跟着一百个零.\(100^{100}\)更是难以想像的大,一后面跟着两百个零.但是尽管这个数字很大,它们各位数字的和却只等于一.考虑两个自 ...
- Project Euler 63: Powerful digit counts
五位数\(16807=7^5\)也是一个五次幂,同样的,九位数\(134217728=8^9\)也是一个九次幂.求有多少个\(n\)位正整数同时也是\(n\)次幂? 分析:设题目要求的幂的底为\(n\ ...
随机推荐
- 孟晓阳:IT运行监控系统设计与使用心得
http://www.cn-healthcare.com/article/20160325/content-482138.html
- 服务器监控(包括性能指标与web应用程序)
http://blog.csdn.net/yao123long/article/details/53142029 http://blog.csdn.net/heyongluoyao8/article/ ...
- EntityFramework:状态变化与方法的关系[转载]
原文地址 一.约定 OnModelCreating 有一些限制需要注意,例如: 1.表名不支持使用标签进行标注 2.最小长度在 OnModelCreating 中不支持 3.正则表达式在 OnMode ...
- bootstrap-table 表头和内容对不齐
问题: bootstrap-table.js 找到 BootstrapTable.prototype.resetView if (this.options.showHeader && ...
- HDU 2912
直线关于球的多次反射,求最后一次反射点 #include <iostream> #include <cstdio> #include <cstring> #incl ...
- Java Word Break(单词拆解)
给定一个字符串 String s = "leetcode" dict = ["leet", "code"]. 查看一下是够是字典中的词语组成 ...
- eclipse导入myeclipse中的web项目
场景:在myeclipse编写的一个简单的电信计费系统项目,后面公用到eclipse,想把它给导入到eclipse中 操作:eclipse中在packag explorer空白处右键>impor ...
- win10查看系统启动项,并且禁用
打开任务管理器,有一个叫做start up的选项卡,里面的东西就是启动项. 右键选中需要disable的,然后禁用.
- html页面、canvas导出图片
背景:项目现场提出将一个html做的图形页面导出为一张图片的需求,在网上搜了一下,发现都不是很全面,所以综合了很多大神的帖子,自己再次封装,以适用项目需求. 所需js库:html2canvas.js( ...
- ettercap + driftnet 实现同网段下流量欺骗
前言: 由于在局域网中,网关会不断地发送 ARP 数据包询问当前是否有新的客户端上线,如果我们可以欺骗当前局域网网段下的主机, 把我们当成网关地址,并且我们把欺骗的流量转发到真正的网关地址,这样我们就 ...