Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >HDOJ1021题 Fibonacci Again 应用求模公式

HDOJ1021题 Fibonacci Again 应用求模公式

作者头像
谙忆
发布于 2021-01-19 03:46:42
发布于 2021-01-19 03:46:42
29800
代码可运行
举报
文章被收录于专栏:程序编程之旅程序编程之旅
运行总次数:0
代码可运行

Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).

Input Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).

Output Print the word “yes” if 3 divide evenly into F(n).

Print the word “no” if not.

Sample Input 0 1 2 3 4 5

Sample Output no no yes no no no

应用求模公式 (1) (a + b) % p = (a % p + b % p) % p (2) (a - b) % p = (a % p - b % p) % p (3) (a * b) % p = (a % p * b % p) % p (4) a ^ b % p = ((a % p)^b) % p 如果不用的话会溢出。 代码:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
using namespace std;

int main()
{
    int a[1000001],i,j,s;
    a[0]=7;a[1]=11;
    for(i=2;i<1000001;i++)
    {
        a[i]=(a[i-1]%3+a[i-2]%3)%3;//只写最后那个%3也可以
    }
    while(~scanf("%d",&s))
    {
        if(a[s]%3==0)
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015/08/21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
POJ 3070 Fibonacci(矩阵快速幂)
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12271 Accepted: 8707 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
ShenduCC
2018/04/26
5120
HDOJ 1157 Who's in the Middle
Problem Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this ‘median’ cow gives: half of the cows give as much or more than the median; half give as much or less.
谙忆
2021/01/19
3990
HDOJ(HDU) 1708 Fibonacci String
Problem Description After little Jim learned Fibonacci Number in the class , he was very interest in it. Now he is thinking about a new thing – Fibonacci String .
谙忆
2021/01/21
2210
PAT 1015 Reversible Primes
1015. Reversible Primes (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system
ShenduCC
2018/04/27
5180
HDUOJ----1250 Hat's Fibonacci
Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5800    Accepted Submission(s): 1926 Problem Description A Fibonacci sequence is calculated by adding the previous two members the s
Gxjun
2018/03/21
6330
HDU 1250 Hat's Fibonacci
Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11104    Accepted Submission(s): 3732 Problem Description A Fibonacci sequence is calculated by adding the previous two members the
Angel_Kitty
2018/04/08
6090
HDOJ(HDU) 2137 circumgyrate the string(此题用Java-AC不过!坑)
Problem Description Give you a string, just circumgyrate. The number N means you just circumgyrate the string N times, and each time you circumgyrate the string for 45 degree anticlockwise.
谙忆
2021/01/21
3170
PAT 甲级 1019 General Palindromic Number(简单题)
1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is
ShenduCC
2018/04/27
9940
HDOJ 1312题Red and Black
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13508 Accepted Submission(s): 8375
谙忆
2021/01/19
3420
HDOJ 1312 (POJ 1979) Red and Black
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can’t move on red tiles, he can move only on black tiles.
谙忆
2021/01/19
3380
POJ 1775 (ZOJ 2358) Sum of Factorials
John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mathematics, logic, quantum physics,meteorology, science, computers, and game theory. He was noted for a phenomenal memory and the speed with which he absorbed ideas and solved problems. In 1925 he received a B.S. diploma in chemical engineering from Zurich Institute and in 1926 a Ph.D. in mathematics from the University of Budapest. His Ph.D. dissertation on set theory was an important contribution to the subject. At the age of 20, von Neumann proposed a new definition of ordinal numbers that was universally adopted. While still in his twenties, he made many contributions in both pure and applied mathematics that established him as a mathematician of unusual depth. His Mathematical Foundations of Quantum Mechanics (1932) built a solid framework for the new scientific discipline. During this time he also proved the mini-max theorem of GAME THEORY. He gradually expanded his work in game theory, and with coauthor Oskar Morgenstern he wrote Theory of Games and Economic Behavior (1944). There are some numbers which can be expressed by the sum of factorials. For example 9,9=1!+2!+3! Dr. von Neumann was very interested in such numbers. So, he gives you a number n, and wants you to tell him whether or not the number can be expressed by the sum of some factorials. Well, it’s just a piece of cake. For a given n, you’ll check if there are some xi, and let n equal to Σ1<=i<=txi!. (t >=1 1, xi >= 0, xi = xj iff. i = j). If the answer is yes, say “YES”; otherwise, print out “NO”. Input
谙忆
2021/01/20
2870
HDU 5652 India and China Origins(并查集)
India and China Origins Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 441    Accepted Submission(s): 133 Problem Description A long time ago there are no himalayas between India and China, the
ShenduCC
2018/04/26
6440
HDU 5652 India and China Origins(并查集)
hdu---1024Max Sum Plus Plus(动态规划)
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15898    Accepted Submission(s): 5171 Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be
Gxjun
2018/03/22
6970
HDOJ/HDU 1250 Hat's Fibonacci(大数~斐波拉契)
Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4) Your task is to take a number as input, and print that Fibonacci number.
谙忆
2021/01/21
3460
HDU 1021 Fibonacci Again
Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 58267    Accepted Submission(s): 27275 Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) =
Angel_Kitty
2018/04/08
6430
HDOJ 1081(ZOJ 1074) To The Max(动态规划)
Problem Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1 x 1 or greater located within the whole array. The sum of a rectangle is the sum of all the elements in that rectangle. In this problem the sub-rectangle with the largest sum is referred to as the maximal sub-rectangle.
谙忆
2021/01/20
2860
HDOJ 1081(ZOJ 1074) To The Max(动态规划)
hdu 4455 Substrings (DP 预处理思路)「建议收藏」
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1727 Accepted Submission(s): 518
全栈程序员站长
2022/07/07
2340
hdu 2473 Junk-Mail Filter (并查集之点的删除)
Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6276    Accepted Submission(s): 1981 Problem Description Recognizing junk mails is a tough task. The method used here consists of
Gxjun
2018/03/26
7780
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-基础练习 Fibonacci数列
        最近的一些文章都可能会很碎,写到哪里是哪里,过一阵子会具体的整理一遍,这里其它的类型题先往后排一排,因为蓝桥最后考的也就是对题目逻辑的理解能力,也就是dp分析能力了,所以就主要目标定在这里,最近的题目会很散,很多,基本上都是网罗全网的一些dp练习题进行二次训练,准备比赛的学生底子薄的先不建议看啊,当然,脑子快的例外,可以直接跳过之前的一切直接来看即可,只需要你在高中的时候数学成绩还可以那就没啥问题,其实,dp就是规律总结,我们只需要推导出对应题目的数学规律就可以直接操作,可能是一维数组,也可能是二维数组,总体来看二维数组的较多,但是如果能降为的话建议降为,因为如果降为起来你看看时间复杂度就知道咋回事了,那么在这里祝大家能无序的各种看明白,争取能帮助到大家。
红目香薰
2023/02/17
2870
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-基础练习 Fibonacci数列
蓝桥杯 入门训练 Fibonacci数列
Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1。
Meng小羽
2019/12/23
2950
相关推荐
POJ 3070 Fibonacci(矩阵快速幂)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验