poj3070 Fibonacci(矩阵快速幂)

GIS图片地理配准与边界矢量化实操指南:从原理到QGIS应用 图片数字化是GIS数据生产中的基础环节,而将扫描图纸、历史影像等栅格数据转化为可分析空间数据,离不开地理配准与边界矢量化两大核心操作。地理配准通过建立像素坐标与真实地理坐标的映射关系,配合合理分布的控制点与合适的变换模型,消除图像形变并赋予空间位置;矢量化则在此基础上将栅格边界转换为点线面要素。二者结合不仅提升数据精度,还为后续叠加分析、面积量算提供可靠基础,广泛应用于国土规划、历史地图数字化和设计图纸入库等场景。本文以QGIS为工具,系统拆解从坐标系选择、控制点采集到影像输出检查的完整配准流程,并对比自动 阅读详情
Fibonacci
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 11520 Accepted: 8188

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

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:


#include <iostream>
#include <cstdio>

using namespace std;

const int mod = 10000;
struct matrix {  //用一个结构体来存矩阵
	int node[2][2];
}ans, tem;

matrix muti(matrix a, matrix b) {  //矩阵a乘b返回结果矩阵
	matrix temp;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			temp.node[i][j] = 0;
			for (int k = 0; k < 2; k++) {
				temp.node[i][j] = (temp.node[i][j] + (a.node[i][k] * b.node[k][j])) % mod;
			}
		}
	}
	return temp;
}

int quick_m(int b) {
	ans.node[0][0] = ans.node[1][1] = 1;  //ans初始化为单位矩阵
	ans.node[0][1] = ans.node[1][0] = 0;
	tem.node[0][0] = tem.node[0][1] = tem.node[1][0] = 1;
	tem.node[1][1] = 0;
	while (b) {   //快速幂使用到矩阵乘法中
		if (b & 1) {
			ans = muti(ans, tem);
		}
		tem = muti(tem, tem);
		b >>= 1;
	}
	return ans.node[0][1];  //注意返回的是F(n)
}

int main()
{
	int n;
	while (~scanf("%d", &n) && n != -1) {
		printf("%d\n", quick_m(n));
	}
	return 0;
}



VScode高效开发STM32:头文件路径配置全解析 本文详细解析了在VScode中高效开发STM32项目的核心步骤——头文件路径配置。针对常见的“找不到头文件”问题,文章深入剖析了IntelliSense的工作原理,并提供了手把手创建和解读c_cpp_properties.json配置文件的完整指南,包括includePath、defines、compilerPath等关键项的设置,帮助开发者彻底解决红色波浪线错误,实现精准的代码提示与跳转。 阅读详情

相关推荐

基于深度学习的图像去雨(Opencv,Pytorch,Cnn)

最近做了一个图像去雨项目,使用的语言为Python,深度学习框架为Pytorch。去雨效果不错,具体请看效果视频!图像去雨(GAN,Opencv,Pytorch)

Czqqwer的博客 2627

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万+

深入解析国家企业征信系统瑞数6vmp算法逆向实战

本文深入解析了国家企业征信系统所采用的双层防护机制,重点聚焦于瑞数6代vmp算法的逆向实战。文章详细拆解了从加速乐521状态码的绕过,到瑞数412挑战的核心算法还原过程,提供了通过动态Hook、日志分析进行算法逆向,并用Python实现自动化请求链的完整技术方案,旨在为安全研究与技术学习提供参考。

yellow的专栏 633

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...

从此爱上猫 209

Twin Builder CFD 示例:构建、验证和评估静态 ROM

通过我们构建、验证和评估静态 ROM 的综合指南,释放 Twin Builder CFD 的潜力。

jkh920184196的博客 1127

新手别怕!用‘东北天’和‘右前上’坐标系,5分钟搞懂惯性导航姿态矩阵(含Python验证代码)

本文通过‘东北天(ENU)’和‘右前上(RFU)’坐标系,详细解析惯性导航中的姿态矩阵概念。包含Python代码验证,帮助新手快速理解坐标变换、欧拉角及旋转矩阵的构建与应用,特别强调有限转动不可交换性与无限转动次序无关的区别。

weixin_29062255的博客 343

POJ 3070 Fibonacci(矩阵快速幂)

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

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

星载SAR的各项指标解读(史上最全)

一、系统指标 系统指标主要指雷达系统的通用的指标,以及和卫星整星相关的指标,主要有一下几项: 工作频段: 雷达体制: 极化方式: 设计s

9311

POJ3070 Fibonacci (矩阵快速幂)

POJ 3070http://poj.org/problem?id=3070 题目大意: 巨大的斐波那契数列,但是这题告诉了一种新的求解方法,即用矩阵相乘求值。 可以发现,其求值即为求{1,1,1,0}这一二阶方阵的n次幂。 于是出现吧——矩阵快速幂。 https://www.cnblogs.com/cmmdc/p/6936196.html#undefined(这篇博文写的非常详细,...

Sensente的博客 303

离散小波变换(概念与应用)

离散小波变换(概念与应用)

weixin_46713695的博客 4423

【PPS便携式移动电源】如何透彻了解便携式移动电源,仅需要十分钟阅读即可

PPS 便携式储能电源的发展前景广阔,受益于户外经济爆发、应急备灾需求提升及 “双碳” 政策支持,全球市场规模预计持续增长,2025 年出货量将达 2380 万台,未来将向大功率大容量、光充一体化、智能化方向发展,还会拓展家庭储能、移动医疗等新场景,同时钠离子电池应用、双向逆变技术升级将进一步推动行业发展。

昔时扬尘处 276

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 725

华为OD机试真题2026双机位C卷 C语言 实现【明日之星选举】

给定一组选票votes。votes[i]代表第 i 张选票的内容,包含一个字符串"zhangsan,hanmei",表示推荐zhangsan为明日之星,反对 hanmei 称为明日之星。赞成或反对使用逗号(,)分割。 给定一个数组n,表示最后将筛选出赞成票最多的n个人,如果赞成票相同,则反对票越少,排序越靠前;如果赞成票和反对票都相同,则按照姓名字典序升序排序。

MISAYAONE的博客 195

poj 3070 Fibonacci 【矩阵快速幂】

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

dxx_111的博客 391

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

[POJ3070]Fibonacci sequence——矩阵+快速幂

斐波那契数列题目描述 斐波那契数列是由如下递推式定义的数列 F0=0F_0=0 F1=1F_1=1 Fn+1=Fn+1+FnF_{n+1}=F_{n+1}+F_n 求这个数列第n项的值对10410^4取余后的结果。

15068475758的博客 1675

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

【poj3070】Fibonacci——矩阵快速幂

题目: Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11954   Accepted: 8486 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, an

CFhM_R's Blog 445

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

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

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

【POJ 3070】Fibonacci(矩阵快速幂) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12333   Accepted: 8752 Description In the Fibonacci integer sequence, F0 = 0,

ACMer' 1425

POJ 3070 Fibonacci (矩阵快速幂)

Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15807 Accepted: 11106 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:

Ever_glow的博客 846

POJ 3070 Fibonacci 矩阵快速幂

题意很明确,求第m个斐波那契数MOD10000的结果 题目连矩阵都构造好了,就是  1   1 1   0 然后对这个求幂就行了 /* ID: sdj22251 PROG: subset LANG: C++ */ #include #include #include #include #include #include #include #include #include

水 3005

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...

恒治学 147

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 terms of the Fibonacci sequence are: 0,1,1,2,3,5,8,13,21,34,…0, 1, ...

NIRVANA REBIRTH 261

POJ 3070 Fibonacci 【矩阵快速幂】

题目连接 : http://poj.org/problem?id=3070—————————————————————————Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12738 Accepted: 9065 DescriptionIn the Fibonacci intege

Tabris的博客 421

poj3070 Fibonacci 矩阵快速幂

Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19733   Accepted: 13621 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2...

cloudy_happy的博客 160

POJ 3070 Fibonacci(矩阵快速幂)

题目地址:POJ 3070 用这个题学会了用矩阵快速幂来快速求斐波那契数。 根据上个公式可知,第1行第2列和第2行第1列的数都是第n个斐波那契数。所以构造矩阵,求快速幂即可。 代码如下: #include #include #include #include #include #include #include #include #include #include

scf0920 1183

(矩阵快速幂)POJ3070Fibonacci

POJ3070Fibonacci 题意&思路: 求斐波那契数列的第n项fn%10000。 矩阵快速幂模板题,题目已经告诉你了矩阵怎么求。 代码: #include<iostream> #include<stdio.h> #include<stdlib.h> #include<algorithm> #include<string.h&gt...

Z7784562的博客 187

【poj3070】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, … ...

lhh的博客 233
上一篇: hdu1257 最少拦截系统
下一篇: 斐波那契数列数组递推,普通递归,记忆化搜索,矩阵快速幂,和公式法
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址