NEFU 115 斐波那契的整除

来源:互联网 发布:c专家编程电子书 编辑:程序博客网 时间:2024/06/02 11:50

斐波那契的整除

Time Limit 1000ms

Memory Limit 65536K

description

已知斐波那契数列有如下递归定义,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整除,你知道吗?

input

输入数据有若干组,每组数据包含一个整数n(1< n <1000000000)。

output

对应每组数据n,若 f(n)能被3整除,则输出“3”; 若f(n) 能被4整除,则输出“4”;如果能被12整除,输出“YES”;否则输出“NO”。

sample_input

46712

sample_output

34NOYES

#include<iostream>using namespace std;int main(){int n;while(cin>>n){int tmp=n%12;switch(tmp){case 1:case 2:case 3:case 5:case 7:case 9:case 10:case 11: cout<<"NO"<<endl; break;case 0: cout<<"YES"<<endl;break;case 4:case 8:cout<<"3\n";break;case 6:cout<<"4\n";break;}}return 0;}


原创粉丝点击