zoukankan      html  css  js  c++  java
  • HDU_1021_费布拉切变形

    Fibonacci Again

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


    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
     
    一来想把数列所有值计算出来,发现数值增长实在太快,到几百的规模时longlong就溢出了。
    然后自己推了一下发现,(a+b)%c==(a%c+b%c)%c,这应该是取模运算的性质。 然后就过了。
     
    #include<iostream>
    #include<cstdio>
    using namespace std;
    #define LL long long
    
    int f[1000005];
    int main()
    {
        f[0]=1;
        f[1]=2;
        int t=2;
        while(t<1000005)
        {
            f[t]=(f[t-1]+f[t-2])%3;
            t++;
        }
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            if(f[n]==0)
                printf("yes
    ");
            else
                printf("no
    ");
        }
        return 0;
    }
  • 相关阅读:
    node.js中常用的fs文件系统
    秒懂 this
    Filter 过滤器
    Ubuntu 安装zookeeper
    Vmware 设置NAT模式
    TreeMap
    ArrayList扩容
    Java 面试题收集
    SwitchyOmega 设置修改代理
    Jedis操作Redis
  • 原文地址:https://www.cnblogs.com/jasonlixuetao/p/5452479.html
Copyright © 2011-2022 走看看