High-precision algorithms

Source: Internet
Author: User

Links: Https://www.nowcoder.com/acm/contest/75/E
Source: Niu Ke Net

Topic Description Given an integer n (0≤n≤10000), the factorial input description of n is obtained:
Multiple test data, each test data input a number n
Output Description:
Each group outputs the factorial of N with one line
Example 1 input
123
Output
126
#include <stdio.h> #include <string.h>int a[50000]; int main () {    int n;    while (~SCANF ("%d", &n)) {        memset (a, 0, sizeof (a));        A[0]=1; A[1]=1;        for (int i=1;i<=n;i++) {for            (int j=1;j<=a[0];j++)                a[j]=a[j]*i;            Int J;            for (j=1;j<=a[0];j++) {                a[j+1]=a[j+1]+a[j]/10;                a[j]=a[j]%10;            }            while (a[j]>0) {                a[j+1]+=a[j]/10;                A[J]%=10;                j + +;                a[0]++;            }        }        for (int i=a[0];i>0;i--)            printf ("%d", A[i]);        printf ("\ n");    }     return 0;}

Save each bit with an array and carry the previous one plus.

High-precision algorithms

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.