Sleepy Kaguya (回归之战)

眼看马上就要到蓝桥杯了,该刷刷题练练手了,找找当年的感觉了!大概快半年没有更新过了,有些算法知识基本都遗忘了,很难受,寒假期间一定要多温习,掌握一些基础的、重要的算法知识!还要多刷题,寻找一些解题的技巧,蓝桥杯一定可以取得满意的成绩的!加油呀!

 

 

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

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

题目描述

Houraisan☆Kaguya is the princess who lives in Literally House of Eternity. However, she is very playful and often stays up late. This morning, her tutor, Eirin Yagokoro was going to teach her some knowledge about the Fibonacci sequence. Unfortunately, the poor princess was so sleepy in class that she fell asleep. Angry Eirin asked her to complete the following task:

This sequence can be described by following equations:
    1.F[1]=F[2]=1

    2.F[n]=F[n-1]+F[n-2]  (n>2)

 

Now, Kaguya is required to calculate F[k+1]*F[k+1]-F[k]*F[k+2] for each integer k that does not exceed 10^18.

Kaguya is so pathetic. You have an obligation to help her.

 

(I love Houraisan Kaguya forever!!!)

image from pixiv,id=51208622

输入描述:

Input
Only one integer k.

输出描述:

Output
Only one integer as the result which is equal to F[k+1]*F[k+1]-F[k]*F[k+2].

示例1

输入

复制

2

输出

复制

1

说明

F[2]=1,F[3]=2,F[4]=3

2*2-1*3=1

备注:

0 < k ≤ 1^18

If necessary, please use %I64d instead of %lld when you use "scanf", or just use "cin" to get the cases.

The online judge of HNU has the above feature, thank you for your cooperation.

思路:一开始感觉题目数据很大,还想着数组要怎么开?思维真的有点跟不上了,后来仔细思考,还是采用打表找规律的办法吧,偶数为1,奇数为-1. (题目较为简单,写这篇文章的用意就是为了宣誓回归,加油)

代码:

///打表找规律
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long LL;
using namespace std;
int main()
{
    LL k;
    scanf("%I64d",&k);
    if(k%2==0)
    {
        cout<<"1"<<endl;
    }
    else
    {
        cout<<"-1"<<endl;
    }
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值