ACM_Fibonacci数(同余)
Problem Description:
斐波那契数列定义如下:f(0)=0,f(1)=1,f(n+2)=f(n+1)+f(n);
求斐波那契数列的第n项对10009取余后的结果。
Input:
多组测试,每组测试输入一个整数n(0<=n<=10^17).
Output:
对于每个测试,输出答案,占一行。
Sample Input:
10
Sample Output:
55
解题思路:运用同余定理:(a+b)%mod=(a%mod+b%mod)%mod。一般像这种取余的题目,答案是有规律的,于是暴力打表,果然发现有循环节数,为3336。注意输入的n已经爆int,要long long,水过。
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int mod = ;
int main()
{
int a[]={,};
for(int i=;i<;++i)
a[i]=(a[i-]%mod+a[i-]%mod)%mod;
long long n;
while(cin>>n)
cout<<a[n%]<<endl;
return ;
}
ACM_Fibonacci数(同余)的更多相关文章
- POJ 3070 + 51Nod 1242 大斐波那契数取余
POJ 3070 #include "iostream" #include "cstdio" using namespace std; class matrix ...
- bjfu1238 卡特兰数取余
题目就是指定n,求卡特兰数Ca(n)%m.求卡特兰数有递推公式.通项公式和近似公式三种,因为要取余,所以近似公式直接无法使用,递推公式我简单试了一下,TLE.所以只能从通项公式入手. Ca(n) = ...
- Sicily1020-大数求余算法及优化
Github最终优化代码: https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1020.c 题目如下: 1020. ...
- LightOJ-1214-Large Division-大数取余
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...
- D-【乐】k进制数(同余)
题目 https://ac.nowcoder.com/acm/contest/907/D 做法 \((x)_k\)定义编号,如果\(a+b\)加到一起能进一位,\(a+b\rightarrow 1+( ...
- SPOJ 370 Ones and zeros BFS + 同余剪枝
题意:给一些n,求出最小的只包含0,1的n的倍数 设两数a, b满足: a < b 并且a % n = b % n. 如果 ( a * 10^x + c ) % n = z , 根据同余定理,( ...
- 由HashMap哈希算法引出的求余%和与运算&转换问题
1.引出问题 在前面讲解HashMap 的源码实现时,有如下几点: ①.初始容量为 1<<4,也就是24 = 16 ②.负载因子是0.75,当存入HashMap的元素占比超过整个容量的75 ...
- sql计算总页数
1 计算总页数方法: public int getTotalCount() { Statement stmt = null; //提交SQL语句对象stmt Resu ...
- [LeetCode] 923. 3Sum With Multiplicity 三数之和的多种情况
Given an integer array A, and an integer target, return the number of tuples i, j, k such that i &l ...
随机推荐
- 1 problem was encountered while building the effective model [FATAL] Non-parseable POM F:\MavenRepository\org\apache\maven\plugins\maven-resources-plugin\2.6\maven-resources-plugin-2.6.pom: start tag
Multiple annotations found at this line: - No plugin found for prefix 'war' in the current project a ...
- [bzoj1500][NOI2005]维修数列[Treap][可持久化Treap]
非旋转式Treap1500 :) #include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; const i ...
- 【周期性执行事件】MySQL事件(Event)&任务调度
1.事件简介 事件(event)是MySQL在相应的时刻调用的过程式数据库对象.一个事件可调用一次,也可周期性的启动,它由一个特定的线程来管理的,也就是所谓的“事件调度器”. 事件和触发器类似,都是在 ...
- vim fulerformat的设置
在vim中设置选项,有注释很容易明白: set laststatus=1 "2总显示最后一个窗口的状态行,1窗口多于一个时显示最后一个窗口的状态行,0不显示最后一个窗口的状态行 fulerf ...
- Linux下汇编语言学习笔记16 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- hdu - 2266 How Many Equations Can You Find (简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2266 给一个字符串和一个数n,在字符串中间可以插入+或者 -,问有多少种等于n的情况. 要注意任意两个数之间都可 ...
- poj_2506_Tiling_201407211555
Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7509 Accepted: 3672 Descriptio ...
- 【进击后端】ubuntu 快速安装node mongodb express
安装软件:node,mongo,express 1.apt install node 2.node -v 3.apt install mongodb 4.mongo -version 5.apt in ...
- [Jexus系列] 一、安装并运行 Jexus
注意,本教程使用的jexus版本为5.8.3专业版,操作系统为 Ubunutu 16.04 64位 一.创建默认站点 不熟悉vim的可以看这个: vim超简单入门教程 sudo mkdir -p /v ...
- 【结果发布】第六届SeedCoder编程大赛初赛结果发布
微软俱乐部科技文化月seedcoder2014编程大赛已经初审完成. 评审小组选出最棒的作品进入决赛(现场答辩+陈述环节,由评委现场打分).终于排名由"初赛分数+现场答辩分"决定. ...