不要自卑,去提升實力
互聯網行業誰技術牛誰是爹
如果文章可以帶給你能量,那是最好的事!請相信自己
加油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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/229797.html
標籤:其他
