列表

详情


NC21182. Sleepy Kaguya

描述

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

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 4ms, 内存消耗: 476K, 提交时间: 2019-01-07 09:48:31

#include<iostream>
using namespace std;
 
int main()
{
    long long n;
    cin>>n;
    cout<<(n%2==1?-1:1);
}

C++11(clang++ 3.9) 解法, 执行用时: 4ms, 内存消耗: 484K, 提交时间: 2019-02-11 18:43:25

#include<stdio.h>
int main()
{long long x;
scanf("%lld",&x);
printf("%d",x%2==0?1:-1);
return 0;}

pypy3(pypy3.6.1) 解法, 执行用时: 34ms, 内存消耗: 20200K, 提交时间: 2020-08-28 16:01:30

if int(input()) % 2 == 0:
    print(1)
else:
    print(-1)

Python3(3.5.2) 解法, 执行用时: 26ms, 内存消耗: 3424K, 提交时间: 2019-01-29 19:42:50

print((-1)**(int(input())))

上一题