1+2!+3!+4!+......+N!这个算法怎么做啊?请高手帮忙,谢谢!

解决方案 »

  1.   

    不就是求和吗?
    long a(int n){
      long sum=0;
      for(int i=0;i<n;i++){
         long t=1;for(int j=0;j<i;j++) t*=j;
         sum+=t;
      }
      return sum;
    }
      

  2.   

    C#    static public long CalcN(long n,out long ntanhao)
        {
            if (n <= 1) return ntanhao = 1;
            return CalcN(n - 1, out ntanhao) + (ntanhao *= n);
        }
      

  3.   

    private static int j = 0;
    public static int getInt(int i){
    if (i==1)
      return 1;
    else 
      return i*getInt(i-1);
    }
    public staic void main(String test[]){
      for (int i=0;i<=n;i++){
        j+=getInt(i);
      }
    }
      

  4.   

    class test
    {
       int sum=0;
       public int jc(int i)
        {
           if(i<=1) return 1;        
           return i
         } 
    }
      

  5.   

    c写的,提供一点算法建议
    #include "stdafx.h"
    #include <iostream>using namespace std;
    int f(int);int _tmain(int argc, _TCHAR* argv[])
    {
    cout<<f(3)<<endl;
    cin.get();
    return 0;
    }int f(int n)
    {
    int t = 0;
    int *d = new int[n+1];
    for (int i=0; i<=n; i++)
    {
    if (i<=1)
    {
    d[i] = 1;
    t += d[i];
    }
    else
    {
    d[i] = d[i-1]*i;
    t += d[i];
    }
    } delete d;
    return t;
    }
      

  6.   

    class  NSum { public static void main(String[] args) {
    NSum ns = new NSum();
    ns.sumNum(3);
    } public int sumNum(int n) {
    int iTotal = 0;
    for(int i = n;i > 0;i--){
    int iSum = 1;
    for(int j = 1;j <= i;j++){
    iSum *= j;
    }
    System.out.println(iSum+"%%%%%");
    iTotal += iSum;
    }
    System.out.println(iTotal);
    return iTotal;
    }
    }
      

  7.   

    错了,是楼上的楼上,也就是believefym(暮色,miss,迷失,miss) 半路杀出来,真是的....嘿嘿~
      

  8.   

    import java.io.*;public class FactorialApp {
    long add ;
    long Factorial(long n){
    long j = 1;
    for(long l = 1;l<=n;l++){
    j*= l;
    }
    return j;
    }
    void  AddFactorial(long n){
    for(long lg = 1;lg<=n;lg++){
    add+=Factorial(lg);
    }
    }
    void Display(){
    System.out.println(add);
    }
    public static void main(String [] args)throws Exception{
    System.out.println("/*  求1!+2!+3!+4!+n!  */");
    FactorialApp fa = new FactorialApp();
    System.out.println("/*  请输入一个数,并求它的阶乘累加 */");
    System.out.print("-->:");
    BufferedReader reader = new BufferedReader
    (new InputStreamReader(System.in));
    int count=Integer.parseInt(reader.readLine());
    fa.AddFactorial(count);
    System.out.print("Efect:");
    fa.Display();
    }}
      

  9.   

    believefym说得不错,递归是不仅费时间,而且费空间