Nyoj 27 Large number factorial

Source: Internet
Author: User
Tags min time limit
large number factorialTime limit: Ms | Memory limit: 65535 KB Difficulty: 3 Description 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. Enter the factorial of an integer m (0<m<=5000) output m and enter a line feed sample input after the output ends
50
Sample output
30414093201713378043612608166064768844377641568960512000000000000

#include "stdio.h"
#define MAXN 18000
int A[MAXN];
int main ()
{
	int m,i,index,c;	0<m<=5000, m=5000 data has 16,326 bits of data 
	scanf ("%d", &m);
	A[0]=1;	index=0; m++;
	if (m>=0 && m<=5000) {
		while (--m)
		{
			c=0;
			for (i=0;i<=index;i++)
			{
				c=m*a[i]+c;		
				a[i]=c%10; c/=10;						
			}
			while (c) {a[++index]=c%10;c/=10;}
		}
	}

	for (i=index;i>=0;i--)
		printf ("%d", A[i]);
	printf ("\ n");
	
	return 0;


Arithmetic idea form as elementary school student formula calculation

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.