Big Data factorial

Source: Internet
Author: User
A-n! Time limit:5000 Ms Memory limit:32768kb 64bit Io format:% I64d & % i64usubmit status

Description

Given an integer N (0 ≤ n ≤ 10000), your task is to calculate n!
 

Input

One N in one line, process to the end of file.
 

Output

For each n, output n! In one line.
 

Sample Input

 123 
 

Sample output

 126 
Array simulation I ran a 10000 data, and the display time-out was not calculated, but the submission was correct, 10000! It's really an astronomical number.
#include<stdio.h>#include<string.h>int main(){int a[101000],n,l;while(~scanf("%d",&n)){memset(a,0,sizeof(a));a[0] =1;l=1;for(int i=1;i<=n;i++){int s = 0,j;for( j=0;j<l||s;j++){  int z= a[j]*i+s;a[j] = z%10;s = z/10;}l=j;//printf("%d\n",l);}for(int j = l-1;j>=0;j--)printf("%d",a[j]);printf("\n");}} 


Related Article

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.