[Click quiz 28] Big Data factorial

Source: Internet
Author: User
Description
We all know how to calculate a factorial of a number. But if this number is large, how should we calculate it and output it?
Input
Enter an integer m (0 <m <= 5000)
Output
Output the factorial of M, and enter a linefeed after the output ends.
Analysis: the number of obvious factorial is relatively large, and INT overflow occurs. Therefore, the int array method is used to store each bit with array elements. According to the multiplication rule, use each bit of the array element to multiply and iterate

# Include <iostream> # include <cstring> # include <cstdlib> using namespace STD; int main () {int arr [20000]; memset (ARR, 0, sizeof (ARR); int m; int COUNT = 0; CIN> m; arr [0] = 1; for (INT I = 2; I <= m; I ++) {for (Int J = 0; j <20000; j ++) {COUNT = arr [J] * I + count; arr [J] = count % 10; Count = count/10;} int I; for (I = 20000-1 ;! Arr [I]; I --); For (; I> = 0; I --) {cout <arr [I] ;}cout <Endl; return 0 ;}


[Click quiz 28] Big Data factorial

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.