牛客小白月赛21 - Fool Problem(Fib、规律)
牛客小白月赛21 - Fool Problem(Fib、规律)
链接:https://ac.nowcoder.com/acm/contest/3947/F
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld
题目描述
Nancy喜欢斐波那契数列!
若f0=0,f1=1,f2=1,请求:fn+1fn−1−fn2(n≥2),其中fi表示斐波那契数列第i项。
输入描述:
共一行:一个整数n。
数据满足:2≤n≤102020。
输出描述:
共一行:表示表达式的值。
输入
2
输出
1
一看这么大的数,看起来没法算,那就找规律吧
很容易看出来,从第二项开始,每个偶数项的平方都比前后两项之积少 1,每个奇数项的平方都比前后两项之积多 1。

#include <bits/stdc++.h> typedef long long LL; const int INF=0x3f3f3f3f; const double eps =1e-8; const int mod=1e8; const int maxn=2e5+10; using namespace std; int main() { #ifdef DEBUG freopen("sample.txt","r",stdin); #endif string n; cin>>n; if(1&(n[n.size()-1]-'0')) cout<<-1<<endl; else cout<<1<<endl; return 0; }
再给出一些结论:

-

浙公网安备 33010602011771号