hdu1021 数学题 并不是说难,而是数学题那种简单朴素的思想get不到

hdu1021 Fibonacci Again

一个斐波那契数列,求f[n]能否被3 整除。

#include<stdio.h>
int main()
{
    long n;
    while(scanf("%ld",&n) != EOF)
       if (n%8==2 || n%8==6)
           printf("yes\n");
       else
           printf("no\n");
    return 0;
}
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
using namespace std;
#define maxn 1000005
int main()
{
    short ans[maxn];
    int n;
    ans[0] = 1;
    ans[1] = 2;
    for(int i = 2;i < 1000000;i ++){
        ans[i] = (ans[i-1] + ans[i-2])%3;
    }
    while(cin >> n){
        if(ans[n] % 3 == 0)
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
    return 0;
}

注:虽然只是15ms 与 0 ms的区别!!!!!!!

posted on 2016-04-27 11:20  Tob's_the_top  阅读(104)  评论(0编辑  收藏  举报

导航