Factorial of the topic 1076:n

Source: Internet
Author: User

Title Description:

Enter a positive integer n to output the factorial of N.

Input:

Positive integer N (0<=n<=1000)

Output:

Input may include multiple sets of data, for each set of input data, the factorial of the output n

Sample input:
4515
Sample output:
241201307674368000
Source:

2006, Tsinghua University computer Research Life Test real problem

#include <iostream> #include <string.h> #include <stdio.h>//code using namespace std with no timeouts;    int main () {int N;    int num[3001];        while (cin >>n) {int i,j,k;        memset (num,0,sizeof (num));        Num[0] = 1;        int length = 1;            if (N = = 0) {cout << 1 <<endl;        Continue             } for (i = 1; i<=n; i++) {int over = 0;                for (j = 0; J < Length, j + +) {Num[j] = num[j] * i + over;                    if (Num[j] >=) {over = Num[j]/10;                NUM[J] = num[j]% 10;            } else over = 0;                } while (over! = 0) {int temp = over% 10;                Num[length + +] = temp;            over = OVER/10;  }} for (i = 3000;i >=0; i--) if (num[i]! = 0) break;      for (j = i; j >= 0; j--) cout<<num[j];    cout << Endl; } return 0;} /************************************************************** problem:1076 User:carvin language:c++ Resul t:accepted time:1320 Ms Memory:1520 kb****************************************************************/


Factorial of the topic 1076:n

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.