Fibonacci POJ - 3070 (矩阵快速幂的模板)

深入剖析:功率放大电路设计精髓——从理论到实践 输入信号首先被调制(通常是PWM脉宽调制)成高频开关信号,驱动功率开关管(MOSFET),再通过LC低通滤波器滤除高频分量,还原出放大的音频信号。在靠近功放板电源引脚处放置足够容量的电解电容(如100uF - 1000uF)和高频瓷片电容(如0.1uF)并联进行电源去耦,抑制低频和高频干扰,防止低频振荡(Motorboating)和高频自激。,堪称电子世界里的“能量转换器”。当输入信号在零附近(即两个器件切换导通的区域)时,由于器件的开启电压(Vbe或Vgs)不为零,输出波形会出现明显的衔接不流畅的失真。 阅读详情

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 Fnare 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
Hint

As a reminder, matrix multiplication is associative, and the product of two 2 × 2 matrices is given by

.

Also, note that raising any 2 × 2 matrix to the 0th power gives the identity matrix:

.


题意:就是求 Fibonacci 数列的第n项的数;

思路:矩阵快速幂,最重要的就是构造式子,

如:在斐波那契数列之中

fi[i] = 1*fi[i-1]+1*fi[i-2]

 fi[i-1] = 1*f[i-1] + 0*f[i-2];

即

所以

代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
#define mod 10000
struct node
{
	ll a[2][2];
};
ll n;

node s_cheng(node tt,node kk)
{
	int i,j,k;
	node c;
	c.a[0][0] = c.a[0][1] = c.a[1][0] = c.a[1][1] = 0;
	for(i=0;i<2;i++)
		for(j = 0;j<2;j++)
			for(k = 0;k<2;k++)
				c.a[i][j] = (c.a[i][j] + tt.a[i][k] * kk.a[k][j])%mod; 
	return c;
}

node jz_pow(node tt,ll n)
{
	node res;
	res.a[0][0] = res.a[1][1] = 1;
	res.a[0][1] = res.a[1][0] = 0;
	while(n)
	{
		if(n&1) res = s_cheng(res,tt);
		n>>=1;
		tt = s_cheng(tt,tt);
	}
	return res;
}
int main()
{
	while(~scanf("%lld",&n)&&n!=-1)
	{
		if(n==0)
		{
			printf("0\n");
			continue;
		} 
		node tt,res;
		tt.a[0][0] = tt.a[0][1] = tt.a[1][0] = 1;
		tt.a[1][1] = 0;
		res.a[0][0] = 1;
		res.a[1][0] = 0;
		tt = jz_pow(tt,n-1);
		res = s_cheng(tt,res);
		printf("%lld\n",res.a[0][0]); 
	}
	return 0;
} 


c#视觉应用开发中如何使用Emgu CV在C#中进行图像处理? Emgu CV 是 OpenCV 的 .NET 包装器,可以让开发者在 .NET 语言(如 C#)中使用 OpenCV 的功能进行图像处理。在进行图像处理时,Emgu CV 提供了丰富的 API 可以使用。PictureBoxImageBox下面是一个详细的示例,演示如何使用 Emgu CV 在 C# 中进行基本的图像处理,包括加载图像、转换为灰度图像、进行边缘检测,然后显示结果。byte在这个示例中,我们使用了三个PictureBox控件来显示原始图像、灰度图像和边缘检测后的图像。 阅读详情

相关推荐

【纯血鸿蒙】安装hdc工具

参考资料:

oh.K 5602

poj 3070 Fibonacci(矩阵加速DP)

Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12459   Accepted: 8853 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn

clover_hxy的博客 832

西门子 S7-200 SMART 系列六:手把手教你配置S7-200 SMART Modbus RTU

最新发表:https://www.ics-pedia.com/%e8%a5%bf%e9%97%a8%e5%ad%90-s7-200-smart-%e7%b3%bb%e5%88%97%e5%85%ad%ef%bc%9a%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e4%bd%a0%e9%85%8d%e7%bd%aes7-200-smart-modbus-rtu%e5%ae%9e%e4%be%8b/

John_09040211的博客 3292

POJ 3070 Fibonacci【矩阵连乘】

Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6881   Accepted: 4873 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn

free斩 1628

WindTerm 安装使用教程

WindTerm是一款Github上开源的 SSH 终端工具,它是完全可以比肩MobaXterm工具的。

m0_69576880的博客 4082

蓝牙AoA技术详解:厘米级定位原理与应用

蓝牙AoA(Angle of Arrival)是一种基于信号到达角度测量的高精度定位技术,通过天线阵列和相位差计算实现亚米级定位。相比传统蓝牙RSSI定位,AoA技术将精度提升至0.1-0.5米范围,适用于工业自动化和商业空间等场景。其核心在于支持连续载波相位检测和IQ采样的蓝牙芯片,结合三角测量算法实现精确定位。随着蓝牙5.1标准的普及,AoA技术正成为室内定位领域的热门解决方案,特别是在需要厘米级精度的AGV调度和智能零售等应用中展现出巨大潜力。

weixin_29185199的博客 211

POJ - 3070 - Fibonacci (矩阵快速幂 + 斐波那契数列)

Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10096   Accepted: 7208 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn

Never say never 4196

别再死记硬背了!用LTspice和Simulink仿真,5分钟搞懂巴特沃斯、切比雪夫、贝塞尔滤波器的区别

本文通过LTspice和Simulink仿真工具,直观对比了巴特沃斯、切比雪夫和贝塞尔滤波器的特性差异。从通带波纹、过渡带陡峭度到相位线性度,详细解析了三种经典滤波器的设计哲学与应用场景,帮助工程师和学生快速掌握滤波器选型技巧,提升电路设计效率。

weixin_33910191的博客 530

Fibonacci( POJ-3070)

Fibonacci( POJ-3070) In the Fibonacci integer sequence,F0= 0,F1= 1, andFn=Fn− 1+Fn− 2forn≥ 2. For example, the first ten terms of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 2...

菜鸡的博客 902

CoppeliaSim和Python进行无人机联合仿真

CopeeliaSim和Python进行无人机轨迹跟踪联合仿真。首先建立起CoppeliaSim和Python的连接,其次在Python中生成轨迹,CoppeliaSim仿真环境中的无人机进行跟踪,并绘制出轨迹曲线,有每一步详细的教学。

加斯顿工程师的博客 995

解决Gradle中NPM命令失效问题

摘要:本文分析了IntelliJ IDEA中Gradle执行npm命令失败的问题,报错显示"npm"文件不存在。通过确认npm安装路径、检查系统PATH与Gradle环境的差异,提出两种解决方案:1) 在build.gradle中使用npm绝对路径;2) 通过launchctl修改用户PATH。实例展示了如何修改Gradle脚本或系统配置来解决该问题,指出跨平台开发中环境变量配置的重要性。文章为开发者提供了处理类似问题的实用方法。

2501_90323865的博客 93

NYOJ148fibonacci数列(二)

fibonacci数列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 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 Fibonacc...

weixin_34174105的博客 281

matlab 点云学习目录【2027最新版】

matlab 点云学习目录。博客长期更新,本文最近更新时间为:2026年12月3日。

点云侠的博客 3万+

poj 3070 Fibonacci(矩阵快速幂模板,斐波那契)

Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12812   Accepted: 9109 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = 

TUT我好菜啊 1958

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

POJ 3070 Fibonacci 矩阵快速幂模板

题目链接 题目大意: 求第n项的斐波那契数对10000求余的结果 解题思路: 矩阵快速幂模板题 矩阵快速幂模板: //用二维vector来表示矩阵 typedef vector<int> vec; typedef vector<vec> mat; typedef long long ll; const int M = 10000; //计算矩阵相乘 mat mul(mat ...

RPG_Zero的博客 238

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

POJ 3070 Fibonacci [矩阵快速幂模板]

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

Vace___yun的博客 209

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

POJ 3070 Fibonacci【矩阵快速幂取模】【模板题】

递推的式子一般都可以化成矩阵相乘的形式。关键的就是构造矩阵, 但这题题目已经构造好了,所以就成了模(shui)板(shu)题了。

AC_Dreameng 1292

poj 3070 <矩阵快速幂【模板】求Fibonacci数列>

Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12950   Accepted: 9209 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn =

leibniz_zhang的博客 518

poj 3070 Fibonacci (矩阵快速幂乘/模板)

题意:给你一个n,输出Fibonacci (n)%10000的结果 思路:裸矩阵快速幂乘,直接套模板 代码: #include <cstdio> #include <cstring> #include <iostream> using namespace std; typedef long long ll; const in...

114

poj3070 Fibonacci(矩阵快速幂模板)

#include<iostream> using namespace std; typedef long long LL; struct mat{ int m[2][2]; }; mat mul(mat a,mat b){ mat ans; for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ ans.m[i][j]=0...

Ellery的book 180

poj 3070 Fibonacci 矩阵快速幂 模板题

矩阵快速幂应该主要在于怎么构造矩阵吧,其他都是模板的。#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define mod 10000 typedef struct { int m[2][2]; }mat; int n; mat mul(ma

liujc_的专栏 400

POJ 3070 Fibonacci(矩阵快速幂)(模板)

传送门 题意:求斐波那契数列的第n项,但是n很大,达到1e9 题解:由于n很大,所以不能逐项递推,采用矩阵快速幂加速递推,如图 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int MOD=1e4; int n; struct Matrix { int v[2][2]; Matrix ()

KGV093的博客 279

POJ 3070 Fibonacci 【矩阵快速幂取模 (模板)】

Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13262   Accepted: 9430 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = 

DTL66的博客 451

POJ3070:Fibonacci(矩阵快速幂模板题)

http://poj.org/problem?id=3070登录后复制 #include <iostream> #include <string.h> #include <stdlib.h> #include <cstdio> #include <algorith...

weixin_33724264的博客 183

hdu 3070 Fibonacci && poj 1575 Tr A(矩阵快速幂模板题)

Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13637   Accepted: 9669 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn =

K键盘里的青春K 736
上一篇: Nested Dolls HDU - 1677 (矩形嵌套问题,先构造序列,再用upper_bound找最长上升子序列+贪心)
下一篇: Seating Arrangement CSU - 1997 (思维题,是否存在n个数的序列,使得相邻啷个数的差绝对值大于d)
obsorb_knowledge
博客等级 码龄9年 38粉丝 213原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址