题目要求1!+2!+3!+4!+...+100000000000000000000000000000000!
一下是我的代码:哪里有问题啊!
//这个程序那里错了
import java.util.*;
import java.math.*;
public class Test5 {
static BigInteger fun1(BigInteger n)
{
BigInteger i;
BigInteger result=1;
for(i=1;i.subtract(n)!=0;i.add(1))
{
result=result.multiply(i);
}
return result;
}
static BigInteger fun(BigInteger n)
{
BigInteger result =0;
BigInteger i=BigInteger.valueOf(1);
for(;i.subtract(n)!=0;i.add(1))
{
result=result.add(fun(i));
}
return result;
}
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
int i = cin.nextInt();
BigInteger n = BigInteger.valueOf(i);
System.out.println(fun(i));
}
}
一下是我的代码:哪里有问题啊!
//这个程序那里错了
import java.util.*;
import java.math.*;
public class Test5 {
static BigInteger fun1(BigInteger n)
{
BigInteger i;
BigInteger result=1;
for(i=1;i.subtract(n)!=0;i.add(1))
{
result=result.multiply(i);
}
return result;
}
static BigInteger fun(BigInteger n)
{
BigInteger result =0;
BigInteger i=BigInteger.valueOf(1);
for(;i.subtract(n)!=0;i.add(1))
{
result=result.add(fun(i));
}
return result;
}
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
int i = cin.nextInt();
BigInteger n = BigInteger.valueOf(i);
System.out.println(fun(i));
}
}
解决方案 »
- 我的jsp文件运行不了
- jsp标签的区别?请教了
- 弱弱的问下,有插件的JAVA程序怎么转成EXE,或者其他直接运行的格式
- 怎样将.class文件变为双击即可执行的文件?
- 常量池的问题
- Gef Undo 问题
- 有关CLASSPATH和package 种类引用的问题请教!
- 急!!在线等!!关于在JPanel上画图形的问题
- 请问如能用java实现GIS那种地图浏览功能,或者介绍一下相关的资料!
- 菜鸟提问:用JBuilder建立一空项目,添加一带有main的类,在main中输入System.Out.Println("Hello World!")运行时怎么什么都没有?
- 怎样把一个String数字转为String小数类型,如100转为1.00
- 求助 这个程序怎么运行不了
long t0, t1;
t0 = System.currentTimeMillis();
BigInteger bi = factorial(99999);
t1 = System.currentTimeMillis();
System.out.println(t1 - t0);
} public static BigInteger factorial(int n) {
if(n < 2) {
return BigInteger.ONE;
}
int[] oddCount = new int[Integer.numberOfTrailingZeros(Integer.highestOneBit(n))];
int shift = init(oddCount, n);
BigInteger result = BigInteger.ONE;
BigInteger bg = BigInteger.ONE;
BigInteger tmp = BigInteger.ONE; int max = oddCount[oddCount.length - 1];
int offset = (oddCount[0] + 1) & 1;
int oddStart = 1;
while(oddStart <= max) {
tmp = tmp.multiply(new BigInteger(String.valueOf(2 * oddStart + 1)));
if(oddCount[offset] == oddStart) {
offset++;
bg = bg.multiply(tmp);
tmp = BigInteger.ONE;
result = result.multiply(bg);
}
oddStart++;
}
return result.shiftLeft(shift);
} private static int init(int[] oddCount, int n) {
int s = n;
int r = 0;
int k = oddCount.length;
while(k > 0) {
s >>= 1;
oddCount[--k] = n - s - 1;
n = s;
r += s;
}
return r;
}
}