• 杭电1021Fibonacci Again


    地址:http://acm.hdu.edu.cn/showproblem.php?pid=1021

    题目:

    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

     思路:(a+b)%c=a%c+b%c,所以可以把F(0)看做1,F(1)看做2,F(3)看做0,可以看出该数列一定会循环,(且最大循环节为9,因为3*3=9)。。。。。。以此类推.

      得到数列 (从0开始)1 2 0 2 2 1 0 1....(后面重复);

      所以。。。用n对8取模就好了。

       取模公式n=(n-1)%8+1;

    ac代码:

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstdio>
     4 #include <cmath>
     5 #include <cstring>
     6 #include <queue>
     7 #include <stack>
     8 #include <map>
     9 #include <vector>
    10 
    11 #define PI acos((double)-1)
    12 #define E exp(double(1))
    13 using namespace std;
    14 
    15 int main (void)
    16 {
    17     int m;
    18     while(scanf("%d",&m)==1)
    19     {
    20         m=(m-1)%8+1;
    21         if(m==2||m==6)
    22             cout<<"yes"<<endl;
    23         else
    24             cout<<"no
    ";
    25     }
    26     return 0;
    27 }
    View Code
  • 相关阅读:
    setsid
    dup
    信号量
    linux标准输入输出
    linux守护进程范例
    c++字符串操作
    浏览器缓存
    bfc
    苹果手机自制铃声
    vue-cli 源码解读
  • 原文地址:https://www.cnblogs.com/weeping/p/5351933.html
Copyright © 2020-2023  润新知