zoukankan      html  css  js  c++  java
  • FatMouse' Trade

    题目

    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

    参考代码

    #include<iostream>
    #include<stdio.h>
    using namespace std;
    int main()
    {
    int a;
    while(scanf("%d",&a))
    {
    if(a%4==2)
    printf("yes
    ");
    else printf("no
    ");
    }
    //太无语了。。。。
    }
    

    错误示例

    #include
    #include<stdio.h>
    using namespace std;
    const int N=1000000;
    int main()
       {
    int F[N],f0=0,f1=1,fn=2,a;
    F[0]=7;
       F[1]=11;
    for(int i=0;i<N-3;i++)
    {
    F[fn]=F[f0]+F[f1];
       fn++;f0++;f1++;
    }
       while(scanf("%d",&a)!=EOF)
    {
    if(F[a]%3)
    printf("no");
    else printf("no");
    }
    }
    

    在这道题目里如果按照求Fibonacci每一项的思路来做,就会超出限制,因此,只能通过找规律来ac。说实话这个规律我也不知道是为什么。。。。

  • 相关阅读:
    U盘支持启动windows和Linux
    emacs安装
    npm 安装指定的第三方包
    npm安装第三方包
    npm 安装淘宝镜像
    ssm 环境搭建
    gitBook安装简介
    git 博客搭建
    git 多人开发
    git ssh提交
  • 原文地址:https://www.cnblogs.com/liuzhanshan/p/5191532.html
Copyright © 2011-2022 走看看