已知斐波那契数列有如下递归定义,f(1)=1,f(2)=1, 且n>=3,f(n)=f(n-1)+f(n-2),它的前几项可以表示为1, 1,2 ,3 ,5 ,8,13,21,34…,现在的问题是想知道f(n)的值是否能被3和4整除,你知道吗?
对应每组数据n,若 f(n)能被3整除,则输出“3”; 若f(n) 能被4整除,则输出“4”;如果能被12整除,输出“YES”;否则输出“NO”。
林大OJ-115
#include <bits/stdc++.h>
using namespace std;
int f[12] = {4, 1, 1, 1, 2, 1, 3, 1, 2, 1, 1, 1};
int main() {
long long n;
while (cin >> n) {
if (f[n % 12] == 4) cout << "YES" << endl ;
else if (f[n % 12] == 1) cout << "NO" << endl ;
else if (f[n % 12] == 2) cout << 3 << endl ;
else if (f[n % 12] == 3) cout << 4 << endl ;
}
return 0;
}