当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5986:Fibonacci

题目描述
We consider the Fibonacci sequence f where f(0) = 0, f(1) = 1 and f(n) = f(n - 1) + f(n - 2) for n ≥ 2. For given x(0), one can define another sequence x that x(n) = f(x(n-1)). Now you need to find the minimum n such that x(n) ≡ x(0) (mod p).
输入解释
The first line contains an integer T indicating the number of test cases. Then for each test case, a line consists of two integers x(0) and p where 0 ≤ x(0) ≤ $10^9$ and 1 ≤ p ≤ 200000.
输出解释
For each test, output the minimum n in a line, or -1 if it is impossible.
输入样例
5
6 4
8 11
9 11
12 11
13 11
输出样例
3
3
-1
1
1
提示
In the first case, x(0) = 6 ≡ 2 (mod 4), x(1) = f(6) = 8 ≡ 0 (mod 4) and x(2) = f(8) = 21 ≡ 1 (mod 4), and therefore x(3) = f(21) = 10946 ≡ 2 (mod 4).
来自杭电HDUOJ的附加信息
Recommend jiangzijing2015

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5986

最后修改于 2020-10-25T23:27:18+00:00 由爬虫自动更新

共提交 1

通过率 0.0%
时间上限 内存上限
8000/4000MS(Java/Others) 65536/65536K(Java/Others)