hdu1021-Fibonacci Again

余数里面的一条公式:(a+b)%3 = (a%3+b%3)%3

 1 #include <iostream>
 2 using namespace std;
 3 int f[1000001];
 4 int main() {
 5      int n;
 6      f[0] = 7;
 7      f[1] = 11;
 8      for (int i = 2; i <= 1000000; i++)
 9       f[i] = (f[i-1]%3 + f[i-2]%3)%3;
10      while(cin>>n) {
11       if (n < 2) cout<<"no"<<endl;
12       else {
13            if (f[n]== 0)
14             cout<<"yes"<<endl;
15            else
16             cout<<"no"<<endl;
17       }
18      }
19      return 0;
20 }
posted @ 2012-04-24 16:45  SkyHacker  阅读(891)  评论(0编辑  收藏  举报