首页 > 其他 > 详细

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

时间:2016-04-27 12:26:18      阅读:274      评论:0      收藏:0      [点我收藏+]

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的区别!!!!!!!

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

原文:http://www.cnblogs.com/zhangjialu2015/p/5438196.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!