HDU 1042

題意:求N的階層,用大數

注意:忽略前導0

#include<stdio.h>
#include<string.h>
int main()
{
    int n,a[100000];
    int i,j,k,count,temp;
    while(scanf("%d",&n)!=EOF)
    {
        memset(a,0,sizeof(a));
        a[0]=1;
        count=1;
        for(i=1; i<=n; i++)
        {
            k=0;
            for(j=0; j<count; j++)
            {
                temp=a[j]*i+k;
                a[j]=temp%10;
                k=temp/10;
            }
            while(k)
            {
                a[count++]=k%10;
                k=k/10;
            }
        }
        for(j=100000-1; j>=0; j--)
        {
            if(a[j])
                break;

        }
        //忽略前導0
        for(i=count-1; i>=0; i--)
        {
            printf("%d",a[i]);
        }
        printf("\n");

    }
    return 0;
}



發佈了41 篇原創文章 · 獲贊 9 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章