Fibonacci Again

题目:

Problem Description

There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11,
F(n) = F(n-1) + F(n-2) (n>=2).

还有另一种Fibonacci数:F(0)=7,F(1)=11,F(n)=F(n-1)+F(n-2)(n>=2)。(另一种斐波那契数)

Input

Input consists of a sequence of lines, each containing an integer
n. (n < 1,000,000).

输入由一系列行组成,每行包含一个整数n(n<1000000)。

Output

Print the word “yes” if 3 divide evenly into F(n). Print
the word “no” if not.

如果3等分为F(n),则打印“yes”。如果没有,请打印“no”。

Sample Input

0

1

2

3

4

5

Sample Output

no

no

yes

no

no

no

解析:其实很多人第一反应会想到写个函数计算把数计算出来,但是这样会出现后面的数字出现负数的情况。这道题的数字有规律:

F(0)=7 7%3=1,不行;
F(1)=11 11%3=2,不行;
F(2)=11+7=18 18%3=0,可行;n%4=2;
F(3)=18+11=29 29%3=2,不行;
F(4)=29+18=47 47%3=2,不行;
F(5)=47+29=76 76%3=1,不行;
F(6)=76+47=123 123%3=0,可行;n%4=2;
…………

也就是说,只要输入的n%4=2就一定会被三等分。
那么代码就简单咯:
#include <stdio.h>
int main(){
 int n;
 while(scanf("%d",&n)!=EOF){
  if(n%4==2) printf("yes\n");
  else printf("no\n");
 }
 return 0;
}
思路果然蛮重要的,这道题其实不是很难。
但是学长和我说这题可以用矩阵快速幂来解决,我试了很久,但自己还是讲不明白,就先搁置了,打算搞懂了再来更新这个题,我会对得起自己的。
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值