sincerit 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

22-13=1
备注:
0 < k ≤ 10^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.

题意给你一个斐波那契数列,求f(k+1)*f(k+1)-f(k)*f(k+2) = ?

看起来这个题目要有大数去做, 用大数去做求出一个斐波那契数都是很耗时,那不一定能过了,被迷惑了,总结一下这些套路:其实是找规律的东西,而且有时候要注意特判的情况

#include <stdio.h>
int main() {
    long long k;
    scanf("%lld", &k);
    if (k % 2 == 0) printf("1");
    else printf("-1");
}

猜你喜欢

转载自blog.csdn.net/sincerit/article/details/85995192