F-Fool Problem

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

Nancy喜欢斐波那契数列!
若f0=0,f1=1,f2=1f ,请求:f{n+1}f{n-1}-fn^2(n≥2),其中fi表示斐波那契数列第i项。

输入描述:
共一行:一个整数n。
数据满足:2≤n≤10^2020。

输出描述:
共一行:表示表达式的值。

输入
2
输出
1
题记:这题数据大到10的2020次方,那就肯定是有规律的。当n为偶数时表达式的值为1,否则为-1。所以直接用字符串形式输入n,然后判断字符串最后一个字符是否为偶数就行了。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    char str[2022];
    cin>>str;
    long long len=strlen(str);
    int sum=str[len-1]-'0';
    if(sum%2==0)
        cout<<"1";
    else
        cout<<"-1";
    return 0;
}

发布了12 篇原创文章 · 获赞 1 · 访问量 217

猜你喜欢

转载自blog.csdn.net/weixin_45809826/article/details/104039461
今日推荐