1021 Fibonacci Again
2016-07-28 22:53
567 查看
nProblem Description
There are another kind of Fibonaccinumbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
nInput
Input consists of a sequence of lines, eachcontaining an integer n. (n < 1,000,000).
nOutput
Print the word "yes" if 3 divideevenly into F(n).
Print the word "no" if not.
nSample input:
0 1 2 3 4 5 6
n
nSample output:
no no yes no no no yes
There are another kind of Fibonaccinumbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
nInput
Input consists of a sequence of lines, eachcontaining an integer n. (n < 1,000,000).
nOutput
Print the word "yes" if 3 divideevenly into F(n).
Print the word "no" if not.
nSample input:
0 1 2 3 4 5 6
n
nSample output:
no no yes no no no yes
#include<iostream> #include<stdio.h> using namespace std; int Fibonacci(int n) { if(n<0) return -1; else if(n ==0) return 7; else if(n ==1) return 11; else return Fibonacci(n-1)+Fibonacci(n-2); } int main(void) { int n; while(scanf("%d",&n) != EOF) { if(Fibonacci(n)%3 == 0) printf("yes "); else printf("no "); } return 0; }
相关文章推荐
- java实现斐波那契数列的3种方法
- java数学归纳法非递归求斐波那契数列的方法
- C++输出斐波那契数列的两种实现方法
- 求斐波那契(Fibonacci)数列通项的七种实现方法
- 斐波那契数列
- OJOJ:斐波那契数列的实现——递归与非递归实现
- 数学公式
- Go语言学习笔记(练习) - 斐波那契数列
- leetcode 虐我篇之(二十一)Climbing Stairs
- 青蛙跳台阶解法 时间复杂度O(n) 空间复杂度O(1)
- 斐波那契数列及相关问题
- 关于斐波那契数列的复杂度最低算法
- 超级台阶
- 矩阵乘法求斐波那契数列
- Tyvj专题 P1337 fibonacci数列
- HDOJ 2044 一只小蜜蜂
- 简单算法之—斐波那契数列
- java编程:三种方法实现斐波那契数列
- java: 四器 之 生成器初学
- 斐波那契数列的算法实现 —— python