HDU1021 Fibonacci Again

来源:互联网 发布:zookeeper 默认端口 编辑:程序博客网 时间:2024/05/29 07:10

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


题目意思:是否f(n)能被3平均分,能就输出yes不能就no.原本以为开个数组,打好表,最后判断是否f(n)== 0 就OK了,谁知道unsight long long 都用了还是wr了。原因数据溢出。最后还是MOD了3.AC了。


代码:

/**************************************** * Author: alei * Created Time: 2015 * project name: HDU1021*****************************************/#include <iostream>#include <stdio.h>#include <time.h>using namespace std;unsigned long long arr[1000005];int main(){    #ifdef LOCAL    freopen("b:\\data.in.txt", "r", stdin);    #endif //LOCAL    unsigned long long n;    arr[0] = 7;    arr[1] = 11;    for(int i=2; i<1000000; i++)    {        arr[i] = (arr[i-1] + arr[i-2]) % 3;    }    while( ~scanf("%I64d", &n))    {        if(arr[n] == 0)            cout<< "yes" <<endl;        else            cout<< "no" <<endl;    }    return 0;}

0 0