大数巨之某种序列
发布时间:2020-12-14 03:09:52 所属栏目:大数据 来源:网络整理
导读:描述 数列A满足An = An-1 + An-2 + An-3,n = 3 编写程序,给定A0,A1 和 A2,计算A99 输入 输入包含多行数据 每行数据包含3个整数A0,A1,A2 (0 = A0,A2 = 100000000) 输出 对于输入的每一行输出A99的值 样例输入 1 1 1 样例输出 69087442470169316923566147 思
描述 1 1 1 样例输出 69087442470169316923566147 思考: 代码如下 import java.math.BigInteger;
import java.util.Scanner;
/** * Created by lcc on 2017/6/1. */
public class Dashujuxulie {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
BigInteger x = scanner.nextBigInteger();
BigInteger y = scanner.nextBigInteger();
BigInteger z = scanner.nextBigInteger();
for (int i = 3; i <= 99; i++) {
BigInteger t = (x.add(y)).add(z);
x = y;
y = z;
z = t;
}
System.out.println(z);
}
}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |