不要自卑,去提升实力
互联网行业谁技术牛谁是爹
如果文章可以带给你能量,那是最好的事!请相信自己
加油o~
点击下面链接
蓝桥杯历届真题题目+解析+代码+答案(2013-2020)(JavaA、B、C组)
题目描述:
给定数列 1, 1, 1, 3, 5, 9, 17, …,从第 4 项开始,每项都是前 3 项的和。求 第 20190324 项的最后 4 位数字。
【答案提交】
这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一 个 4 位整数(提示:答案的千位不为 0),在提交答案时只填写这个整数,填写 多余的内容将无法得分。
解题思路:
> 和菲波那切数列差不多
> 因为项数过大,所以使用BigInteger
代码:
public class Main {
public static void main(String[] args){
BigInteger a=BigInteger.ONE;
BigInteger b=BigInteger.ONE;
BigInteger c=BigInteger.ONE;
BigInteger d=BigInteger.ONE;
int n=20190324;
for(int i=3;i<n;i++) {
d=a.mod(new BigInteger("10000")).add(b.mod(new BigInteger("10000"))).add(c.mod(new BigInteger("10000")));
a=b;
b=c;
c=d;
}
System.out.println(d.mod(new BigInteger("10000")));
}
}
答案:
4659