"Large number factorial" NYOJ-28

Source: Internet
Author: User

Large number factorial time limit:MS | Memory limit:65535 KB Difficulty:3
Describe
we all know how to calculate the factorial of a number, but if the number is large, how do we calculate it and output it?
Input
Enter an integer m (0<m<=5000)
Output
The factorial of the output m and enter a newline character after the output ends
Sample input
50
Sample output
30414093201713378043612608166064768844377641568960512000000000000
Code
1 //NYOJ-28 large number factorial2 //directly open an array large enough to simulate a vertical operation, carry. 3#include <cstdio>4#include <cstring>5 Const intMAXN =20000;6 intF[MAXN];7 intMain () {8     inti,j,n,s,c;9scanf"%d", &n);TenMemset (F,0,sizeof(f)); Onef[0] =1; A      for(i =2; I <= N; i++) { -c =0; -         //Rounding the          for(j =0; J < Maxn; J + +) { -s = f[j] * i +C; -F[J] = s%Ten; -c = S/Ten; +         } -     } +      for(j = maxn-1; J >=0; j--)if(F[j]) Break; A      for(i = j; I >=0; i--) printf ("%d", F[i]); atprintf"\ n"); -     return 0; -}

 

"Large number factorial" NYOJ-28

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.