zoukankan      html  css  js  c++  java
  • hdu 1042 N!

    N!

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
    Total Submission(s): 66786    Accepted Submission(s): 19147


    Problem 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
    1
    2
    3
     
    Sample Output
    1
    2
    6
     
    Author
    JGShining(极光炫影)
     
    Recommend
    We have carefully selected several similar problems for you:  1715 1047 1063 1753 1316 
     
    基础的大数问题,注意进位,将数字全部压入数组保存。
     
    题意:求n!,必须大数。
     
    附上代码:
     
     1 #include <cstdio>
     2 #include <iostream>
     3 using namespace std;
     4 int main()
     5 {
     6     int i,j,n,k,s,m,t;
     7     int a[100005];      //保存n!
     8     while(~scanf("%d",&n))
     9     {
    10         a[0]=1;
    11         s=1;    //记录数组的位数
    12         for(i=1; i<=n; i++)
    13         {
    14             k=0;       //记录进位的值
    15             for(j=0; j<s; j++)  //每一位都要乘以i
    16             {
    17                 t=a[j]*i+k;
    18                 a[j]=t%10;    //只保留个位数
    19                 k=t/10;      //去掉最后一位
    20             }
    21             while(k)        //将k的值全部压入数组
    22             {
    23                 a[s++]=k%10;
    24                 k/=10;
    25             }
    26         }
    27         for(i=s-1; i>=0; i--) //注意倒着输出
    28             printf("%d",a[i]);
    29         printf("
    ");
    30     }
    31     return 0;
    32 }
  • 相关阅读:
    zipalign内存对齐优化
    反编译 waring...
    android.os.NetworkOnMainThreadException
    android:LayoutInflater
    Notification NotificationManager RemoteViews PendingIntent
    WebView WebViewClient WebChromeClient
    寒假1
    冻死可怕了
    一个人失眠
    军训快乐
  • 原文地址:https://www.cnblogs.com/pshw/p/4813381.html
Copyright © 2011-2022 走看看