hdu 1021 Fibonacci Again(变形的斐波那契)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1021

Fibonacci Again

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 70782    Accepted Submission(s): 32417

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

Author

Leojay

Recommend

JGShining   |   We have carefully selected several similar problems for you:  1061 1108 1071 1049 1032

分析:

别多想

直接暴力即可,开始还想找规律来着

注意求第i项的时刻记得模3

不然会溢出(w了两次。。。gg)

code:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define max_v 1000005
LL f[max_v];
int main()
{
    f[0]=7;
    f[1]=11;
    for(LL i=2;i<max_v;i++)
    {
        f[i]=(f[i-1]%3+f[i-2]%3)%3;
    }
    LL n;
    while(~scanf("%I64d",&n))
    {
        if(f[n]%3==0)
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/yinbiao/p/9313404.html

时间: 2024-08-28 05:29:44

hdu 1021 Fibonacci Again(变形的斐波那契)的相关文章

HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)

Fibonacci again and again Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的: F(1)=1; F(2)=2; F(n)=F(n-1)+F(n-2)(n>=3); 所以,1,2,3,5,8,13……就是菲波那契数列. 在

hdu 1316 How many Fibs?(高精度斐波那契数)

//  大数继续 Problem Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := fn-1 + fn-2 (n >= 3) Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a, b]. Input The input contains several test cas

HDU 4639 Hehe(字符串处理,斐波纳契数列,找规律)

题目 //每次for循环的时候总是会忘记最后一段,真是白痴.... //连续的he的个数 种数 //0 1 //1 1 //2 2 //3 3 //4 5 //5 8 //…… …… //斐波纳契数列 //不连续的就用相乘(组合数)好了 #include<iostream> #include<algorithm> #include<string> #include <stdio.h> #include <string.h> #include &l

HDU 2516 取石子游戏 (斐波那契博弈)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2516 1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍.取完者胜.先取者负输出"Second win".先取者胜输出"First win". Input输入有多组.每组第1行是2<=n<2^31. n=0退出. Output先取者负输出"Second win". 先取者胜输

HDU 5914 Triangle(打表——斐波那契数的应用)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Problem Description Mr. Frog has n sticks, whose lengths are 1,2, 3?n respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides t

题解报告:hdu 2516 取石子游戏(斐波那契博弈)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2516 Problem Description 1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍.取完者胜.先取者负输出"Second win".先取者胜输出"First win". Input 输入有多组.每组第1行是2<=n<2^31. n=0退出. Output 先取者负输出"S

【TOJ 3600】Fibonacci II (对数+斐波那契通项式)

描述 2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列(f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2))的值全部给背了下来.接下来,CodeStar决定要考考他,于是每问他一个数字,他就要把答案说出来,不过有的数字太长了.所以规定超过4位的只要说出前4位就可以了,可是CodeStar自己又记不住.于是他决定编写一个程序来测验zouyu说的是否正确. 输入 输入若干数字n(0 <= n <=

斐波那契查找原理详解与实现

最近看见一个要求仅使用加法减法实现二分查找的题目,百度了一下,原来要用到一个叫做斐波那契查找的的算法.查百度,是这样说的: 斐波那契查找与折半查找很相似,他是根据斐波那契序列的特点对有序表进行分割的.他要求开始表中记录的个数为某个斐波那契数小1,即n=F(k)-1;  开始将k值与第F(k-1)位置的记录进行比较(及mid=low+F(k-1)-1),比较结果也分为三种  1)相等,mid位置的元素即为所求  2)>   ,low=mid+1,k-=2;说明:low=mid+1说明待查找的元素在

hdoj 2516 取石子游戏(斐波那契博弈)

Problem Description 1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍.取完者胜.先取者负输出"Second win".先取者胜输出"First win". Input 输入有多组.每组第1行是2<=n<2^31. n=0退出. Output 先取者负输出"Second win". 先取者胜输出"First win". 参看Samp