CF1853B.Fibonaccharsis
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ntarsis has received two integers n and k for his birthday. He wonders how many fibonacci-like sequences of length k can be formed with n as the k -th element of the sequence.
A sequence of non-decreasing non-negative integers is considered fibonacci-like if fi=fi−1+fi−2 for all i>2 , where fi denotes the i -th element in the sequence. Note that f1 and f2 can be arbitrary.
For example, sequences such as [4,5,9,14] and [0,1,1] are considered fibonacci-like sequences, while [0,0,0,1,1] , [1,2,1,3] , and [−1,−1,−2] are not: the first two do not always satisfy fi=fi−1+fi−2 , the latter does not satisfy that the elements are non-negative.
Impress Ntarsis by helping him with this task.
输入格式
The first line contains an integer t ( 1≤t≤2⋅105 ), the number of test cases. The description of each test case is as follows.
Each test case contains two integers, n and k ( 1≤n≤2⋅105 , 3≤k≤109 ).
It is guaranteed the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case output an integer, the number of fibonacci-like sequences of length k such that the k -th element in the sequence is n . That is, output the number of sequences f of length k so f is a fibonacci-like sequence and fk=n . It can be shown this number is finite.
输入输出样例
输入#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 4 valid fibonacci-like sequences for n=22 , k=4 :
- [6,8,14,22] ,
- [4,9,13,22] ,
- [2,10,12,22] ,
- [0,11,11,22] .
For n=3 , k=9 , it can be shown that there are no fibonacci-like sequences satisfying the given conditions.
For n=55 , k=11 , [0,1,1,2,3,5,8,13,21,34,55] is the only fibonacci-like sequence.