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

19510번 - Easy Homework 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.5 초 256 MB10422912.857%

문제

Let us fix an integer $A$. Consider a sequence $\{f(n)\}$ which satisfies the following two conditions:

  1. $f(0) = 0,ドル $f(1) = 1$;
  2. $f(n) = A \cdot f(n - 1) + f(n - 2)$ for any integer $n > 1$.

Given a prime $p$ and an integer $x$ (0ドル \leq x \leq p$), your task is to calculate $|\{n : L \leq n \leq R, \ f(n) \bmod p = x\}|,ドル that is, the number of indices $n$ between $L$ and $R$ such that $f(n) \bmod p = x$.

입력

There are one or more test cases.

The first line of input contains an integer $T,ドル the number of test cases (1ドル \leq T \leq 42)$.

Each of the next $T$ lines contains five integers $A,ドル $p,ドル $x,ドル $L$ and $R$ (0ドル \leq A < 10^{9},ドル 2ドル < p < 10^{9},ドル 0ドル \leq x < p,ドル 1ドル \leq L \leq R \leq 10^{18}$). It is guaranteed that $p$ is prime.

출력

Print $T$ lines, one for each test case, containing the answers to the problem.

제한

예제 입력 1

2
1 5 0 1 5
2 29 12 3 6

예제 출력 1

1
2

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2016 > Day 8: DPRK Contest E번

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

출처

대학교 대회

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

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