杭电ACM 1005 javaA number sequence is defined as follows:f(1)

杭电ACM 1005 java
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).
The input consists of multiple test cases.Each test case contains 3 integers A,B and n on a single line (1
xwd0820 1年前 已收到1个回答 举报

再不见风烟 幼苗

共回答了18个问题采纳率:72.2% 举报

if (a < 1 && a > 1000 && b < 1 && b > 1000 && b < 1 && a > 100000000)
System.exit(0);
这句你用的是& 不对 还有就是你这个做法不行 BigInteger f[] = new BigInteger[n]; 当n=100000000时开不了这么大的数组 时间复杂度也不行 必定超时

1年前 追问

5

xwd0820 举报

如果不用数组用什么保存f(n)呢?泛型行吗?还是其他的什么?
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 18 q. 0.130 s. - webmaster@yulucn.com