牛客小白月赛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

题目描述

Nancy喜欢斐波那契数列!
f0=0,f1=1,f2=1,请求:fn+1fn1fn2(n2),其中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;
}

 

再给出一些结论:

 

-

posted @ 2020-04-13 01:16  jiamian22  阅读(326)  评论(0编辑  收藏  举报