Factorial of a large number


Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 977M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, C, C++, C11, CLANG, CLANGX, Classical, COBOL, Coffee, CSC, D lang, DART, F95, FORTH, Fortrn, GAS32, GO, Haskell, Itercal, Java, kotlin, LEAN, LISP, LUA, MONOVB, Nasm, OCAML, Pascal, Perl, php, PIKE, prolog, Pypy, Python, Ruby 2, RUST, Scala, SCM, SED, SWIFT, TCL, TUR, V8JS, VB, ZIG

Enter a positive integer n \((1 \le n \le 1000)\). Your task prints out the values of n factorials according to the formula \[ n! = \prod \limits_ {i = 1} ^ {n} {i} = 1 * 2 * 3 * ... * n \]

Input

A positive integer n \((1 \ le n \ le 1000)\)

Output

A positive integer is the value of n factorials

Example 1

Input

32

  Output

263130836933693530167218012160000000

Example 2

Input

101

  Output

94259477598383594208516231244829367495623127947025437683278893534169775993162214765030878615918083469116234900035495995833697063026032640000000000000000000000000000
tichpx

Comments


  • 1
    TICHPX  commented on Oct. 25, 2017, 3:07 p.m.

    code tham khảo

    #include<stdio.h>
    #include<string.h>
    
    void mult(char *x,int k)
    {
        int n=0;
        char *p;
        for(p=x;*p;p++)
        {
            n+=(*p-'0')*k;
            *p=n%10+'0';
            n=n/10;
        }
        while(n>0)
        {
            *p++=n%10+'0';
            n/=10;
        }
        *(p+1)=0;
    }
    
    int main()
    {
        int n;
        char x[100005]="1";
        scanf("%d",&n);
        for(int i=2;i<=n;i++) 
        mult(x,i);  
        int nn=strlen(x);
        for(int i=0,j=nn-1;i<j;i++,j--)
        {
            char t=x[i]; x[i]=x[j];x[j]=t;
        }
        printf("%s",x);
    }