当前位置:网站首页>C - Fibonacci sequence again

C - Fibonacci sequence again

2022-07-07 23:39:00 Yuesi

Original link

There is another Fibonacci sequence :
F0=7,F1=11,Fn=Fn−1+Fn−2 (n>=2).

Input format
The input data consists of multiple lines , On each line is an integer
n(n≤10^6).

Output format
If Fn Can be 3 to be divisible by , Then print a line "yes", otherwise , Print a row "no".

Tips
First use the array 1∼10^6 Of Fi
Work it out , Then every time you query , Otherwise it will time out .

The sample input
0
1
2
3
4
5
Sample output
no
no
yes
no
no
no

#include<bits/stdc++.h>
using namespace std;
int main(){
    
	long long int ans[1000006]={
    0};// Store data  
	ans[0]=7;
	ans[1]=11;
	for(long long int i=2;i<=1000001;i++){
    
		ans[i]=ans[i-1]%3+ans[i-2]%3;
		// Just judge whether it can be 3 Divisible and easy to explode longlongint
		// Therefore, there is no need to store the specific data of fibola series  
	}
	long long int n;
	while(scanf("%lld",&n)!=EOF){
    
		if(ans[n]%3==0){
    
			printf("yes\n");
		}else{
    
			printf("no\n");
		}
	}
	return 0;
}

 Pit point :
 Large amount of data and easy to exceed the data range longlongint Range 
原网站

版权声明
本文为[Yuesi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130556375188.html