HDU 1021.Fibonacci Again【规律】【不可直接求】【8月18】

Fibonacci Again

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

F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).给定一个n,f[n]%3==0 就输出yes,否则输出no。不能直接做的,不然超出数的范围。我打出0~40的数跟可不可以被3整除如下图所示:

你会发现,可以的n-2可以被4整除。代码如下:

#include<cstdio>
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        if((n-2)%4==0) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

另外记录一下最近在HDU   A题的情况:

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-20 10:10:19

HDU 1021.Fibonacci Again【规律】【不可直接求】【8月18】的相关文章

HDU 1021[Fibonacci Again]规律

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1021 题目大意:首两项为7,11的斐波那契数列.若第n项能被3整除,输出yes,否则输出no 关键思想:模三加法情况有限,找规律. 代码如下: #include <iostream> using namespace std; int main(){ int n; while(cin>>n) if(n%8==2||n%8==6)cout<<"yes"<

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 ki

hdu 1021 Fibonacci Again 找规律

Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 51448    Accepted Submission(s): 24346 Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n)

HDU 1021 Fibonacci Again 数学题

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

杭电 HDU 1021 Fibonacci Again

Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 41156    Accepted Submission(s): 19705 Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n)

HDU 1021 - Fibonacci Again

找规律,分析让 F[N] 每一项对 3 取余的余数: 1,2,0, 2,2,1,0, 1,1,2,0, 2,2,1,0, 1,1,2,0, 2,2,1,0 ......... 显然循环了 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int n; 6 while(cin>>n){ 7 if(n%4==2) cout<<"yes"<<endl; 8 else

HDU - 1848 - Fibonacci again and again

先上题目: Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4964    Accepted Submission(s): 2072 Problem Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1)=1;F

HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵快速幂)

HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵快速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意: 求第n个斐波那契数的前四位和后四位. 不足8位直接输出. 分析: 前四位有另外一题HDU 1568,用取对的方法来做的. 后四位可以用矩阵快速幂,MOD设成10000就行了. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * Blog: http://blog.csdn.

HDU 1517 A Multiplication Game (博弈-求sg)

A Multiplication Game Problem Description Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and