- 原题链接:Here!
- 思路:
n<1,000,000,肯定不能直接去求F[n],已知 F[n] = F[n-1] + F[n-2] ,根据同于基本性质F[n]≡F[n-1]+F[n-2] ( mod 3 ) ,故预选处理F[ ] 再判断。
(a+b) mod c = ((a mod c) + (b mod c)) mod c - 代码:
#include<bits/stdc++.h> using namespace std; const int maxn = 1000000+10; int fb[maxn]; void init(){ fb[0]=7; fb[1]=11; for(int i=2;i<maxn;i++){ fb[i] = ( fb[i-1]%3 + fb[i-2]%3 ) % 3; } } int main(){ init(); int n; while(cin>>n){ if(fb[n]%3==0) printf("yes\n"); else printf("no\n"); } return 0; }