一个斐波那契数列,求f[n]能否被3 整除。
#include<stdio.h> int main() { long n; while(scanf("%ld",&n) != EOF) if (n%8==2 || n%8==6) printf("yes "); else printf("no "); 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的区别!!!!!!!