主题:Fibonacci Again
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).
Input
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).
Output
Print the word "yes" if 3 divide evenly into F(n).
Print the word "no" if not.
Sample Input
0
1
2
3
4
5
Sample Output
no
no
yes
no
no
no
#include<iostream>
using namespace std;
void main()
{ int n;
while(cin>>n){
float a=7,b=11,c;
if (n==0) b=7;
if(n==1) b=11;
for(int i=2;i<=n;i++){
c=b;
b=a+b;
if (b<0) cout<<b<<endl;
a=c;
}
if(__int64 (b)%3==0) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
}
验证可以,但是总是提交不成功,求助高手,还有一种方法%4=2,已想到,只要知道这个为什么错,怎么改?
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).
Input
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).
Output
Print the word "yes" if 3 divide evenly into F(n).
Print the word "no" if not.
Sample Input
0
1
2
3
4
5
Sample Output
no
no
yes
no
no
no
#include<iostream>
using namespace std;
void main()
{ int n;
while(cin>>n){
float a=7,b=11,c;
if (n==0) b=7;
if(n==1) b=11;
for(int i=2;i<=n;i++){
c=b;
b=a+b;
if (b<0) cout<<b<<endl;
a=c;
}
if(__int64 (b)%3==0) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
}
验证可以,但是总是提交不成功,求助高手,还有一种方法%4=2,已想到,只要知道这个为什么错,怎么改?