编程介的小学生 2017-09-27 23:03 采纳率: 20.5%
浏览 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 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?