湖南大学第十四届ACM程序设计大赛 C Sleepy Kaguya

编程入门 行业动态 更新时间:2024-10-24 18:26:10

湖南大学第十四届ACM程序<a href=https://www.elefans.com/category/jswz/34/1758301.html style=设计大赛 C Sleepy Kaguya"/>

湖南大学第十四届ACM程序设计大赛 C Sleepy Kaguya

链接:
来源:牛客网
时间限制: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]=32*2-1*3=1

备注:

0 < k ≤ 10^18If 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[1]=F[2]=1,F[n]=F[n-1]+F[n-2],

输入一个数k代表第k个斐波那契数,让你求 F[k+1]*F[k+1]-F[k]*F[k+2]的结果,暴力肯定是不行了,斐波那契数的递增速度非常快,且数据范围k是1e18.尝试递推几次后会发现结果不是-1就是1,奇数为-1,偶数为1,后来看了热心博友STZG发的题解才明白原理,感谢申哥的指导!

递推公式:

G(k)=F[k+1]*F[k+1]-F[k]*F[k+2]

=F[k+1]*F[k+1]-F[k]*(F[k]+F[k+1])

=(F[k+1]-F[k])*F[k+1]-F[k]*F[k]

=F[k-1]*F[k+1]-F[k]*F[k]

所以G(k)=-G(k-1)

#include<iostream>
using namespace std;
int main()
{unsigned long long a;cin>>a;if(a&1)cout<<"-1"<<endl;elsecout<<"1"<<endl;
}

 

更多推荐

湖南大学第十四届ACM程序设计大赛 C Sleepy Kaguya

本文发布于:2024-02-25 15:03:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1699370.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设计大赛   四届   湖南大学   程序   Kaguya

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!