0
点赞
收藏
分享

微信扫一扫

nyoj114 某种序列(大数)


  • 题目114
  • ​​题目信息​​
  • ​​运行结果​​
  • ​​本题排行​​
  • ​​讨论区​​

某种序列



3000 ms  |  内存限制: 65535



4



数列A满足An = An-1 + An-2 + An-3, n >= 3 

编写程序,给定A0, A1 和 A2, 计算A99


输入包含多行数据 

每行数据包含3个整数A0, A1, A2 (0 <= A0, A1, A2 <= 100000000) 


数据以EOF结束

输出 对于输入的每一行输出A99的值 样例输入

1 1 1

样例输出

69087442470169316923566147

java做的  :

import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
while(input.hasNext())
{
BigInteger x=input.nextBigInteger();
BigInteger y=input.nextBigInteger();
BigInteger z=input.nextBigInteger();
BigInteger t=new BigInteger("0");
for(int i=3;i<=99;i++)
{
t=(x.add(y)).add(z);
x=y;
y=z;
z=t;
}
System.out.println(t);
}
}

}



举报

相关推荐

0 条评论