1277: Fibonacci Again发表时间:2022-10-27 19:28 1277: Fibonacci Again时间限制: 1 Sec 内存限制: 128 MB 题目描述There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2) 输入Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000) 输出Print the word "yes" if 3 divide evenly into F(n). 样例输入 Copy0 1 2 3 4 5 样例输出 Copyno no yes no no no #include<bits/stdc++.h> using namespace std; int main(){ int a[1000005];int cnt=2; a[0]=7;a[1]=11; for(;cnt<1000000;cnt++) a[cnt]=(a[cnt-1]+a[cnt-2])%3; cnt--; // printf("%d\n",cnt); int n; while(scanf("%d",&n)!=EOF){ if(a[n]%3==0) printf("yes\n"); else printf("no\n"); } return 0; } 上一篇3070: 瓜瓜学几何
下一篇1264: 找男朋友
文章分类:
算法例题
|