Logo
(追記) (追記ここまで)

18652번 - Fibonacci Strikes Back 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB4000.000%

문제

In this problem, you need to solve a well-known problem about P-Fibonacci sequence:

\[F_n = \begin{cases} 0 & \text{if }n = 0 \\ 1 & \text{if } n = 1 \\ PF_{n-1} + F_{n-2} & \text{otherwise} \end{cases}\]

Now given \(P\), \(m\) and the lowest \(k\) decimal digits of \(F_{F_n}\), you are asked to determine the minimum possible \(n\) such that \(n \ge m\) and \(F_{F_n}\) has at least \(k\) lowest decimal digits as given above, or report it is impossible otherwise.

입력

The input contains several test cases. The first line contains an integer \(T\) indicating the number of test cases. The following describes all test cases. For each test case:

The only line contains two integers \(P\), \(m\) and a string of length \(k\), consisting of only digits, which represents the lowest \(k\) decimal digits of \(F_{F_n}\). Note the string may contain leading zeros.

출력

For each test case, output a line containing “Case #x: y” (without quotes), where x is the test case number starting from 1, and y is the minimum possible n to this test case if it exists, or y is −1 otherwise.

제한

  • \(1 \le T \le 10^4\)
  • \(1 \le P, m ≤ 10^{18}\)
  • \(1 \le k \le 18\)
  • The sum of \(k\) in all test cases does not exceed \(10^4\).
  • It is guaranteed that the greatest common divisor of \(P\) and \(10^{18}\) is less than \(5\) for each test case.

예제 입력 1

7
1 3 1
1 4 1
1 6 01
1 1 45
2 1 0482149
998 244 353
998244 1 353

예제 출력 1

Case #1: 3
Case #2: 6
Case #3: 101
Case #4: 10
Case #5: 5
Case #6: -1
Case #7: 233

힌트

When \(P = 1, \{F_{F_n}\}_{n=0}^{\infty} = \{0, 1, 1, 1, 2, 5, 21, 233, 10946, 5702887, 139583862445, \dots\}\).

When \(P = 2, \{F_{F_n}\}_{n=0}^{\infty} = \{0, 1, 2, 29, 13860, 44560482149, \dots\}\).

출처

Camp > Petrozavodsk Programming Camp > Summer 2019 > Day 8: Jingzhe Tang Contest 2, XIX Open Cup Onsite C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /