日期:2014-05-20 浏览次数:20849 次
public class Temp{
public static void main(String[] args) {
System.out.println(zong(5));
}
public static int zong(int n){
//计算若干个多项式的总和
//如计算(1!) + (1! + 2!) + (1! + 2! + 3!)的数值
//(1!) + (1! + 2!) + (1! + 2! + 3!) + (1! + 2! + 3! + 4!)的数值
int result = 0;
for(; n > 0; n--){
result += duo(n);
}
return result;
}
public static int duo(int n){
//计算每一个多项式(1! + 2! + ... + n!)的数值
//如计算(1!)的数值,(1! + 2!)的数值
//(1! + 2! + 3!)的数值
int result = 0;
for(; n > 0; n--){
result += jie(n);
}
return result;
}
public static int jie(int n){
//计算每一个单独的n!的数值(阶乘)
//如计算1!的数值,2!的数值,3!的数值
int result = 1;
for(; n > 0; n--){
result *= n;
}
return result;
}
}