zoukankan      html  css  js  c++  java
  • hdu 1021 Fibonacci Again ——同余的简单性质

    Fibonacci Again

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


    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
     
    先预处理。根据同余的性质求解。
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 using namespace std;
     6 int f[1000000];
     7 void pre(){
     8   f[0] = 7 % 3; f[1] = 11 % 3;
     9   for (int i = 2; i <= 1000000; ++i){
    10     f[i] = (f[i-1] % 3 + f[i-2] % 3) % 3;
    11   }
    12 }
    13 int main(void){
    14   int n;
    15 #ifndef ONLINE_JUDGE
    16   freopen("hdu1021.in", "r", stdin);
    17 #endif
    18   pre();
    19   while (~scanf("%d", &n)){
    20     if (f[n]){
    21       printf("no\n");
    22     }
    23     else printf("yes\n");
    24   }
    25   return 0;
    26 }

    水题……

  • 相关阅读:
    虚幻4目录文件结构
    虚幻4编译手记
    几个重要的坐标系
    关于(void**)及其相关的理解
    装饰器总结篇(持续更新ing)
    Linux中find常见用法示例
    linux grep命令
    linux下IPTABLES配置详解
    分布式数据库中间件DDM的实现原理
    消息队列应用场景解析
  • 原文地址:https://www.cnblogs.com/liuxueyang/p/2992396.html
Copyright © 2011-2022 走看看