POJ 3070 —— Fibonacci 【矩阵快速幂】

从零到一:NI USB-8506 LIN通讯的驱动安装与硬件调试全攻略 本文详细介绍了NI USB-8506 LIN通讯设备的驱动安装与硬件调试全流程,包括硬件准备、驱动下载与配置、NI MAX设置及常见问题解决方案。通过实战应用与性能优化技巧,帮助用户快速掌握LIN通讯技术,适用于车载数据记录和自动化测试等场景。 阅读详情
Fibonacci
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 12190 Accepted: 8651

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 <cstdio>
#include <iostream>
#include <vector>
#include <assert.h>
using namespace std;

const int MOD = (int)1e4;

struct Mat {
    vector<vector<int> > m;
    Mat() {}
    Mat(int a, int b) {
        m.resize(a);
        for(int i=0; i<m.size(); i++) {
            m[i].resize(b);
        }
    }
};

Mat operator * (const Mat& a, const Mat& b) {
    assert(a.m[0].size() == b.m.size());
    Mat c(a.m.size(), b.m[0].size());
    for(int i=0; i<a.m.size(); i++) {
        for(int j=0; j<b.m[0].size(); j++) {
            c.m[i][j] = 0;
            for(int k=0; k<b.m.size(); k++) {
                c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j] % MOD) % MOD;
            }
        }
    }
    return c;
}

Mat operator ^ (Mat a, int k) {
    assert(a.m.size() == a.m[0].size());
    Mat c(a.m.size(), a.m.size());
    
    for(int i=0; i<a.m.size(); i++) {
        for(int j=0; j<a.m.size(); j++) {
            c.m[i][j] = (i==j);
        }
    }
    
    while(k) {
        if(k&1) {
            c = c * a;    
        }
        a = a * a;
        k>>=1;
    }
    return c;
}

int main ()
{
    int n;
    Mat a(2,2), b(2,1);
    a.m[0][0]=a.m[1][0]=a.m[0][1]=1;
    a.m[1][1]=0;
    
    b.m[0][0]=1;
    b.m[1][0]=0;
    
    while(scanf("%d", &n) != EOF && n != -1) {
        if(n==0)    printf("%d\n", b.m[1][0]);
        else if(n==1)    printf("%d\n", b.m[0][0]);
        else {
            Mat ans = (a^(n-1)) * b;
            printf("%d\n", ans.m[0][0]);
        }
    }
    
    return 0;
}

 

基于深度学习YOLOv8的花卉检测与识别系统(附完整资源+PySide6界面+训练代码) 通过本项目,我们成功实现了基于YOLOv8的花卉检测与识别系统,涵盖了数据预处理、模型训练、推理与实时检测、以及GUI界面的实现。YOLOv8在花卉检测中的高效性和准确性为实际应用提供了强有力的支持。 阅读详情

相关推荐

Python新手必看:5分钟搞定睿尔曼机械臂基础控制(附代码示例)

本文为Python新手提供了快速上手睿尔曼机械臂基础控制的实战指南。通过详细的步骤讲解和代码示例,介绍了从环境搭建、网络配置、SDK安装到建立连接、执行关节运动(movej)、直线运动(movel)等核心控制指令的全过程,帮助零基础开发者快速实现机械臂的基础操控。

hp777的博客 343

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 alternative formula for the Fibonacci sequence is . ...

hjc的博客 366

SAP-QM-质检操作

SAP-QM-质检操作

yanzibing99的博客 8211

【题解】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...

翻过这座山,他们就会听到你的故事 501

全面分析总结解决Could not transfer artifact org.apache.maven.plugins等此类问题的方法

全面分析总结解决Could not transfer artifact org.apache.maven.plugins,Could not transfer artifact xxx from/to xxx等此类问题的方法

ccjjjjdff的博客 1万+

从仿真到流片:手把手教你优化65nm CMOS电荷泵的电流匹配与稳定性

本文详细介绍了在65nm CMOS工艺下优化电荷泵电流匹配与稳定性的工程实践指南。通过蒙特卡洛仿真、运放反馈结构版图技巧和全差分结构设计,实现优于1%的电流匹配精度和±2%以内的电流稳定性,特别针对current mismatch问题提供了有效的解决方案。

weixin_42522320的博客 425

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 alternative formula for the Fibonacci sequence is Given an in

kitalekita的博客 286

Unity动态创建Avatar骨骼映射

Unity Avatar骨骼映射动态创建,适配Unity通用动画,无需经过第三方建模软件,可运行时创建

Nbin_Newby的博客 1万+

Fibonacci(矩阵快速幂)

DescriptionIn 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

辞树 590

使用spacy规则化提取自然语言文本信息

1. 安装spacy pip install spicy spicy还需要载入文本库,使用pip的下载方式: python3 -m spacy download en_core_web_sm 但是很有可能因为网络问题下载速度非常缓慢,所以可以选择到github上去直接下载(注意和自己的spacy版本匹配):github下载链接 下载*.tar.gz文件即可。 然后切换到下载路径, pip install en_core_web_sm-3.1.0.tar.gz 2. spacy的一些基础用法 使用spa

六六六六神的博客 1825

【OpenClaw从入门到精通】第24篇:OpenClaw Skill商业化实战指南——从0开发付费技能,在ClawHub变现(2026实测版)

本文聚焦OpenClaw Skill商业化的全流程落地,基于2026年生态现状、公开行业报告及开发者指南,拆解付费Skill的市场机会、商业模式、技术实现、发布运营及避坑要点。核心围绕“Freemium API Backend”主流路径,通过虚拟但贴合真实场景的“金融研报复现”案例,提供从需求分析、定价设计到代码开发、ClawHub上架的完整实操方案。文中包含可直接复用的代码片段、执行结果演示及流程图解,既满足新手快速入门的需求,也为进阶开发者提供商业化落地的关键思路,帮助读者抓住AI Agent早期红利。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 1110

矩阵快速幂——Fibonacci(POJ-3070)

题目 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 alternat...

weixin_45261389的博客 753

基于YOLOv8的城市违建识别系统:从数据集构建到UI界面实现

YOLOv8是Ultralytics公司于2023年推出的最新一代YOLO(You Only Look Once)系列目标检测算法。更高效的骨干网络设计改进的锚框机制更精确的损失函数支持分类、检测、分割等多任务YOLOv8特别适合像违建识别这样的实时检测任务,能够在保持高精度的同时实现快速推理。

YOLO 687

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

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

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

inori mmd 7z

楪祈的模型资源....................................................................................................................................................................................................................

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

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

[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

【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

【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

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 (矩阵快速幂)

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 【矩阵快速幂】

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

Tabris的博客 421

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
上一篇: HDU 1848 —— Fibonacci again and again 【博弈 sg函数】
下一篇: HDU 4734 —— F(x)
AcIsFun
博客等级 码龄11年 1粉丝 92原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址