CF1853B.Fibonaccharsis

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Ntarsis has received two integers nn and kk for his birthday. He wonders how many fibonacci-like sequences of length kk can be formed with nn as the kk-th element of the sequence.

A sequence of non-decreasing non-negative integers is considered fibonacci-like if fi=fi−1+fi−2f_i = f_{i-1} + f_{i-2} for all i>2i \gt 2, where fif_i denotes the ii-th element in the sequence. Note that f1f_1 and f2f_2 can be arbitrary.

For example, sequences such as [4,5,9,14][4,5,9,14] and [0,1,1][0,1,1] are considered fibonacci-like sequences, while [0,0,0,1,1][0,0,0,1,1], [1,2,1,3][1, 2, 1, 3], and [−1,−1,−2][-1,-1,-2] are not: the first two do not always satisfy fi=fi−1+fi−2f_i = f_{i-1} + f_{i-2}, the latter does not satisfy that the elements are non-negative.

Impress Ntarsis by helping him with this task.

Ntarsis 生日收到了两个整数 nn 和 kk。他想知道:有多少个长度为 kk 的斐波那契型序列,使得 nn 恰好是该序列的第 kk 项。

一个非递减的非负整数序列被称为斐波那契型序列,当且仅当对所有 i>2i > 2,均满足 fi=fi−1+fi−2f_i = f_{i-1} + f_{i-2},其中 fif_i 表示序列中第 ii 个元素。注意:f1f_1 和 f2f_2 可以任取(非负整数)。

例如,序列 [4,5,9,14][4,5,9,14] 和 [0,1,1][0,1,1] 是斐波那契型序列;而 [0,0,0,1,1][0,0,0,1,1]、[1,2,1,3][1, 2, 1, 3] 和 [−1,−1,−2][-1,-1,-2] 则不是:前两个序列并非对所有 i>2i>2 都满足 fi=fi−1+fi−2f_i = f_{i-1} + f_{i-2},最后一个序列不满足“所有元素均为非负整数”的条件。

请帮助 Ntarsis 解决这一问题,给他留下深刻印象!

输入格式

The first line contains an integer tt (1≤t≤2⋅1051 \leq t \leq 2 \cdot 10^5), the number of test cases. The description of each test case is as follows.

Each test case contains two integers, nn and kk (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5, 3≤k≤1093 \leq k \leq 10^9).

It is guaranteed the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤2⋅1051 \leq t \leq 2 \cdot 10^5),表示测试用例的数量。每个测试用例的描述如下。

每个测试用例包含两个整数 nn 和 kk(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5,3≤k≤1093 \leq k \leq 10^9)。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case output an integer, the number of fibonacci-like sequences of length kk such that the kk-th element in the sequence is nn. That is, output the number of sequences ff of length kk so ff is a fibonacci-like sequence and fk=nf_k = n. It can be shown this number is finite.

对每个测试用例,输出一个整数,表示长度为 kk 且第 kk 项为 nn 的斐波那契类序列的个数。即,输出满足如下条件的长度为 kk 的序列 ff 的个数:ff 是一个斐波那契类序列,且 fk=nf_k = n。可以证明该数目是有限的。

输入输出样例

  • 输入#1

    8
    22 4
    3 9
    55 11
    42069 6
    69420 4
    69 1434
    1 3
    1 4

    输出#1

    4
    0
    1
    1052
    11571
    0
    1
    0

说明/提示

There are 44 valid fibonacci-like sequences for n=22n = 22, k=4k = 4:

  • [6,8,14,22][6,8,14,22],
  • [4,9,13,22][4,9,13,22],
  • [2,10,12,22][2,10,12,22],
  • [0,11,11,22][0,11,11,22].

For n=3n = 3, k=9k = 9, it can be shown that there are no fibonacci-like sequences satisfying the given conditions.

For n=55n = 55, k=11k = 11, [0,1,1,2,3,5,8,13,21,34,55][0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] is the only fibonacci-like sequence.

对于 n=22n = 22、k=4k = 4,存在 44 个合法的斐波那契式序列:

  • [6,8,14,22][6,8,14,22],
  • [4,9,13,22][4,9,13,22],
  • [2,10,12,22][2,10,12,22],
  • [0,11,11,22][0,11,11,22]。

对于 n=3n = 3、k=9k = 9,可以证明不存在满足给定条件的斐波那契式序列。

对于 n=55n = 55、k=11k = 11,唯一的一个斐波那契式序列为 [0,1,1,2,3,5,8,13,21,34,55][0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]。

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

首页