早教吧 育儿知识 作业答案 考试题库 百科 知识分享

一道ACM题求大神指导是怎么推出周期的?ProblemDescriptionAnumbersequenceisdefinedasfollows:f(1)=1,f(2)=1,f(n)=(A*f(n-1)+B*f(n-2))mod7.GivenA,B,andn,youaretocalculatethevalueoff(n).InputTheinputconsis

题目详情
一道ACM题求大神指导是怎么推出周期的?
Problem Description A number sequence is defined as follows:f(1) = 1,f(2) = 1,f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A,B,and n,you are to calculate the value of f(n).Input The input consists of multiple test cases.Each test case contains 3 integers A,B and n on a single line (1
▼优质解答
答案和解析
因为f(n)只有七中取值0-6,系数a对应7个,b对应7个,A * f(n - 1) + B * f(n - 2)) 只有49个不同值,为一个周期,只要开一个数组储存这49个值mod 7的余数就好了,然后用n%49,来算