poj 3070 Fibonacci

题目连接

http://poj.org/problem?id=3070   

Fibonacci

Description

In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …

An alternative formula for the Fibonacci sequence is

.

Given an integer n, your goal is to compute the last 4 digits of Fn.

Input

The input test file will contain multiple test cases. Each test case consists of a single line containing n (where 0 ≤ n ≤ 1,000,000,000). The end-of-file is denoted by a single line containing the number −1.

Output

For each test case, print the last four digits of Fn. If the last four digits of Fn are all zeros, print ‘0’; otherwise, omit any leading zeros (i.e., print Fn mod 10000).

Sample Input

0
9
999999999
1000000000
-1

Sample Output

0
34
626
6875

裸的矩阵快速幂。。

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
using std::min;
using std::sort;
using std::pair;
using std::swap;
using std::vector;
using std::multimap;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cls(arr, val) memset(arr, val, sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
const int M = 10000;
const int N = 1000000;
const int INF = 0x3f3f3f3f;
struct Matrix {
    typedef vector<int> vec;
    typedef vector<vec> mat;
    inline mat mul(mat &A, mat &B) {
        mat C(sz(A), vec(sz(B[0])));
        rep(i, sz(A)) {
            rep(k, sz(B)) {
                rep(j, sz(B[0])) {
                    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
                }
            }
        }
        return C;
    }
    inline mat pow(mat &A, int n) {
        mat ret(sz(A), vec(sz(A[0])));
        rep(i, sz(A)) ret[i][i] = 1;
        while(n) {
            if(n & 1) ret = mul(ret, A);
            A = mul(A, A);
            n >>= 1;
        }
        return ret;
    }
    inline void solve(int n) {
        mat ans(2, vec(2));
        ans[0][0] = 1, ans[0][1] = 1;
        ans[1][0] = 1, ans[1][1] = 0;
        ans = pow(ans, n);
        printf("%d\n", ans[1][0]);
    }
}go;
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w+", stdout);
#endif
    int n;
    while(~scanf("%d", &n) && ~n) {
        go.solve(n);
    }
    return 0;
}

转载于:https://www.cnblogs.com/GadyPu/p/4773441.html

BLDC&PMSM电机控制器硬件设计工程(一)概述&需求&规划 这里是一个专注于电机控制器硬件工程的开放社区与知识仓库。我们的核心使命是分享、交流与共创,致力于解开无刷直流电机(BLDC)和永磁同步电机(PMSM)中、大功率控制器硬件设计,包括驱动IC选型,电流传感器选型,控制IC,母线电容计算,功率模块(IGBT、MOS管)选型以及大功率功率模块驱动电源设计。功率等级: 重点关注中等功率(如500W-10kW) 并向大功率(10kW以上) 延伸,探讨对应的功率器件(如MOSFET, IGBT, SiC)选型与驱动。 阅读详情

相关推荐

MFC下使用C++操作Word文档

由于项目需求,在MFC环境下操作将数据和图片写入word文档,之前没有接触过,网上查阅了很多资料,终于把任务完成。理解的不是很透彻,但是这些东西应该够用了,写篇博客记录一下,以便以后再用到。 (1)VS环境下创建一个MFC应用程序,然后在项目上单击右键,选择 类向导-----添加类----类型库中的MFC类。在弹出的对话框中选择文件,位置选择office安装目录下的...

GIS_yuhua的博客 7577

poj3070Fibonacci

poj3070Fibonacci:http://poj.org/problem?id=3070 Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11699   Accepted: 8306 Description In the

hahaAll的博客 473

AI驱动的iOS逆向工程自动化:14阶段工作流与Ghidra集成实践

逆向工程是软件安全分析的核心技术,通过反汇编、调试等手段解析程序内部逻辑与数据流。其原理在于将编译后的二进制代码还原为可理解的逻辑结构,从而发现潜在漏洞或理解软件行为。在移动安全领域,iOS逆向工程具有重要技术价值,能够用于安全审计、漏洞挖掘与恶意软件分析。传统iOS逆向依赖ipsw、class-dump、Frida等工具链组合,存在学习曲线陡峭与流程碎片化问题。本文介绍的ios-reverse-skills项目创新性地将14阶段逆向工程方法论封装为AI可调用的标准化脚本集,通过Ghidra脚本实现Swif

weixin_27268733的博客 432

POJ 3070 Fibonacci

POJ 3070 Fibonacci POJ入口:http://poj.org/problem?id=3070 使用模版【模版】矩阵快速幂 AC代码 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; #d...

恒治学 145

emqx Java 订阅以及发送 结合若依框架

emqx Java 订阅以及发送 结合若依框架

Spo的博客 1613

ns3-gym入门(二):linear-mesh例子详解

学习ns3-gym中关于IEEE 802.11网状网络中控制随机接入的例子linear-mesh

zoe2222226666的博客 1843

poj 3070 Fibonacci(简单矩阵连乘)

题目:http://poj.org/problem?id=3070 Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10994   Accepted: 7823 Description In the Fibonacci inte

theArcticOcean 664

[Dify] 法律文档解析助手怎么做才敢用?先把条款提取、依据核对和人工复核分开

这篇文章围绕用 Dify 搭建法律文档解析助手时最容易被忽略的可靠性问题展开:文档能上传、模型能总结,并不等于结果就能直接用于法务判断。文章会从文档抽取、条款定位、召回片段核对、结构化输出和人工复核几个角度梳理设计思路,适合正在用 Dify 处理合同、制度、招投标文件或企业知识库问答的读者阅读。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 9379

POJ 3070 Fibonacci (矩阵快速幂)

In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … An alterna

光明~~~ 2万+

非结构化数据在大数据湖中的应用实践

想象一下,你正在整理一个杂乱的书房。有些书整整齐齐地放在书架上,每本书都有明确的标题、作者和出版日期——这些就是结构化数据,它们像数据库中的表格,有固定的格式和字段。但书房里还有更多东西:散落的照片、手写的笔记、录音带、视频光盘、甚至还有画作。这些物品没有固定的格式,每件都独一无二——这就是非结构化数据。在技术术语中,非结构化数据是指没有预定义数据模型或组织形式的信息。文本文档(Word、PDF、TXT)电子邮件和社交媒体内容图像和照片(JPG、PNG)音频文件(MP3、WAV)

软件工程实践的博客 361

ADS基础教程24 - Gerber文件的导入

一、引言二、基本概念1.仿真文件下载2.仿真文件介绍二、导入步骤1.新建workspace2.选择Layout结构3.导入设计4.选择文件类型5.导入文件6.预览文件内容7.铜皮离散问题四、总结选择。通过本文章结束,可以了解ADS中如何将导入Gerber文件,并且对导入的铜皮进行合并。下一步就针对导入的文件进行层叠设置和编辑。END!}}END!

XZ_ZC的博客 3053

Fibonacci POJ 3070

Fibonacci POJ 3070 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10096 Accepted: 7208 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n...

king9666的博客 314

✨在Windows11上安装虚拟机(VMware17.6.0)保姆级教程(附安装包)

VMware Workstation Pro 是一款功能强大的虚拟机软件,它允许你在单一的物理机上运行多个操作系统。性能卓越:VMware以其出色的性能和稳定性而闻名,适合运行资源密集型的虚拟机。用户友好:直观的用户界面使得即使是初学者也能快速上手。功能全面:支持多种操作系统,包括Windows、Linux、macOS等,满足不同用户的需求。企业级支持:VMware提供全面的技术支持,适合企业级用户。恭喜你成功安装了VMware Workstation Pro 17.6.0!

Python老吕的博客 1万+

[POJ3070]Fibonacci

传送门POJ3070 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13...

Beginner_df016 351

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

POJ3070Fibonacci 矩阵快速幂

POJ3070原题 [url]http://poj.org/problem?id=3070[/url] 如图,Fibonacci矩阵解法: [img]http://dl.iteye.com/upload/attachment/0072/1923/62d5e015-eb0c-3aac-b108-8bedb1676fbe.png[/img] [code="java"] imp...

从此爱上猫 207

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

【poj3070】 Fibonacci

http://poj.org/problem?id=3070 (题目链接)题意:用矩阵乘法求fibonacci数列的第n项。Solution   矩乘入门题啊,题目把题解已经说的很清楚里= =。   矩乘其实很简单,通过自己YY或者是搜索对于一个递推公式求出它所对应的矩阵,然后套个快速幂就可以迅速求解第n项。代码:// poj3070 #include<algorithm> #include<i

MashiroSky的博客 524

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

矩阵十题【六】 poj3070 Fibonacci

矩阵

100days 899

poj 3070 Fibonacci (快速矩阵幂)

#include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cmath&gt; #include &lt;iostream&gt; #include &lt;cstring&gt; using namespace std; const int n = 2; const int mod = 10000; int a[3][3], ...

GaoJieVery6 222

【POJ3070】Fibonacci

题意 求Fibn mod m的值 m=10000,0<=0<=2*109 分析 矩阵快速幂模板 设f(n)={Fibn,Fibn+1},可得到单位矩阵为{(0,1)(1,1) } 代码 #include<iostream> #include<cstdio> #include<cstring> #include<...

Ashley_2013的博客 190

Poj 3070 Fibonacci

Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26063 Accepted: 17394 文章目录Description题意:题解:代码: Poj 3070 Fibonacci Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten t

qq_35975367的博客 411

[POJ] 3070 Fibonacci

http://poj.org/problem?id=3070 求fib第n项 裸矩阵快速幂,练手 #include<iostream> #include<cstring> #include<cstdio> using namespace std; const int MOD=10000; inline int rd()...

weixin_34127717的博客 97

poj_3070 Fibonacci

题目链接:http://poj.org/problem?id=3070   //C++代码 #include using namespace std; const int Mod=10000; struct Matrix{ int a[2][2]; }origin,res; Matrix multiply(Matrix x,Matrix y){ Matrix temp; temp.

永恒国度 616

poj3070 Fibonacci 数论专题

数论,对于我只一个初中生来说,确实比较需要智商。。。最近老师布置数论题,我就在努力奋斗(虽然决定要马上写替罪羊树),替罪羊树是什么?我也不知道,只知道是一个平衡树,怎么写?看这篇博客吧(写这道poj3070时还木有写:) 大概就这样吧,然后就木有然后了,怪我喽!!! 题目是这样子的:题意很明确,求第m个斐波那契数MOD10000的结果 easy到了极点,我居然都没有写矩阵快速幂。。。直接水过(

跳动的量子 1056

POJ 3070 Fibonacci(矩阵快速幂)

题目地址:http://poj.org/problem?id=3070 思路:矩阵快速幂和快速幂的思想差不多,快速幂详解地址:http://blog.youkuaiyun.com/qq_25605637/article/details/47357119,按照下面2张图来就行 AC代码: #include #include #include #include #include #incl

Java识堂,一个有干货的微信公众号 472

POJ3070 Fibonacci【矩阵快速幂】

Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20098 Accepted: 13850 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For exam...

海岛Blog 722
上一篇: poj 2887 Big String
下一篇: poj 3080 Blue Jeans
dong12276
博客等级 码龄13年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值