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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章