牛客小白月赛21 - Fool Problem(Fib、规律)

链接:https://ac.nowcoder.com/acm/contest/3947/F
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

Nancy喜欢斐波那契数列!
f0=0,f1=1,f2=1,请求:fn+1fn1fn2(n2),其中fi表示斐波那契数列第i项。

输入描述:

共一行:一个整数n。
数据满足:2≤n≤102020

输出描述:

共一行:表示表达式的值。

输入

2

输出

1

一看这么大的数,看起来没法算,那就找规律吧

很容易看出来,从第二项开始,每个偶数项的平方都比前后两项之积少 1,每个奇数项的平方都比前后两项之积多 1。

斐波那契数列   

 1 #include <bits/stdc++.h>
 2 typedef long long LL;
 3 const int INF=0x3f3f3f3f;
 4 const double eps =1e-8;
 5 const int mod=1e8;
 6 const int maxn=2e5+10;
 7 using namespace std;
 8 
 9 int main()
10 {
11     #ifdef DEBUG
12     freopen("sample.txt","r",stdin);
13     #endif
14     
15     string n;
16     cin>>n;
17     if(1&(n[n.size()-1]-'0')) cout<<-1<<endl;
18     else cout<<1<<endl;
19     
20     return 0;
21 }

再给出一些结论:

-

猜你喜欢

转载自www.cnblogs.com/jiamian/p/12689014.html