CF193E.Fibonacci Number

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

John Doe has a list of all Fibonacci numbers modulo 1013. This list is infinite, it starts with numbers 0 and 1. Each number in the list, apart from the first two, is a sum of previous two modulo 1013. That is, John's list is made from the Fibonacci numbers' list by replacing each number there by the remainder when divided by 1013.

John got interested in number f (0 ≤ f < 1013) and now wants to find its first occurrence in the list given above. Help John and find the number of the first occurence of number f in the list or otherwise state that number f does not occur in the list.

The numeration in John's list starts from zero. There, the 0-th position is the number 0, the 1-st position is the number 1, the 2-nd position is the number 1, the 3-rd position is the number 2, the 4-th position is the number 3 and so on. Thus, the beginning of the list looks like this: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...

约翰·多伊(John Doe)有一个所有斐波那契数对 10131013 取模后构成的列表。该列表是无限长的,起始于数字 00 和 11。列表中除前两个数外,每个数均为其前两个数之和对 10131013 取模的结果。换言之,约翰的列表是通过对标准斐波那契数列中的每个数除以 10131013 后取余数而得到的。

约翰对某个数 ff(其中 0≤f<10130 \leq f < 1013)产生了兴趣,现在他希望找出该数在上述列表中首次出现的位置。请帮助约翰找出数 ff 在该列表中首次出现的下标;若 ff 并未出现在列表中,则说明该数不存在于列表中。

约翰的列表下标从零开始计数:第 00 位是数字 00,第 11 位是数字 11,第 22 位是数字 11,第 33 位是数字 22,第 44 位是数字 33,依此类推。因此,该列表开头部分为:0, 1, 1, 2, 3, 5, 8, 13, 21, …0,\,1,\,1,\,2,\,3,\,5,\,8,\,13,\,21,\,\dots

输入格式

The first line contains the single integer f (0 ≤ f < 1013) — the number, which position in the list we should find.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

第一行包含一个整数 ff(0 ≤ f < 10130 ≤ f < 10^{13})—— 我们需要在列表中查找该数的位置。

请注意,在 C++ 中不要使用 %lld 说明符来读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 说明符。

输出格式

Print a single number — the number of the first occurrence of the given number in John's list. If this number doesn't occur in John's list, print -1.

输出一个数字——给定数字在约翰列表中首次出现的位置编号。如果该数字未在约翰的列表中出现,则输出 -1。

输入输出样例

  • 输入#1

    13

    输出#1

    7
  • 输入#2

    377

    输出#2

    14

输入解题思路,AI测评打分。不知道怎么写?

首页