编程介的小学生 2017-09-27 23:03 采纳率: 0.2%
浏览 729
已采纳

Easy Homework

Problem Description
Let’s consider a sequence {f(n)} which satisfies following 2 conditions.

1.f(0)=0,f(1)=1.
2.f(n)=Af(n−1)+f(n−2),for any integer n>1.
Here A is a constant integer.

Given a prime p and an integer x(0≤x≤p) , your task is to calculate |{n|L≤n≤R,f(n) mod p=x}| , i.e. the number of indices n between L and R such as f(n) mod p=x .

Input
There are several test cases.

The first line of the input contains an integer T(1≤T≤120) , the number of test cases.

Each of the next T lines contains 5 integers, A,p,x,L,R(0≤A<109,2<p<109,0≤x<p,1≤L≤R≤1018)

Output
Print T lines, containing the answer to the problem.

Sample Input
2
1 5 0 1 5
2 29 12 3 6

Sample Output
1
2

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-16 02:14
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?