一道ACM题求大神指导是怎么推出周期的?
问题描述:
一道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,来算