zoukankan      html  css  js  c++  java
  • hdu 1042 N!(大数的阶乘)

    N!

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 55659    Accepted Submission(s): 15822


    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
     
    这个题目就是一个大数的乘法,不难,但是半年前的我写这个题目的时候写了很长很长的代码 麻烦的很 花了很久才过的  ,现在想起来就重新写了一遍 代码精简了好多,而且也美观了很多 ,哈哈 事实证明我这半年还是有进步的  O(∩_∩)O!
     
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 
     5 using namespace std;
     6 
     7 #define ll long long
     8 
     9 int num[80000];
    10 
    11 int main()
    12 {
    13     int n;
    14     while(~scanf("%d",&n))
    15     {
    16         memset(num,0,sizeof(num));
    17         num[0]=1;
    18         int pre=0;
    19         int len=1;
    20         for(int i=2;i<=n;i++)
    21         {
    22             pre=0;
    23             for(int j=0;j<len;j++)
    24             {
    25                 num[j]=num[j]*i+pre/10;
    26                 pre=num[j];
    27                 num[j]%=10;
    28             }
    29             while(pre>9)
    30             {
    31                 num[len]=pre/10%10;
    32                 len++;
    33                 pre/=10;
    34             }
    35         }
    36         for(int i=len-1;i>=0;i--)
    37         printf("%d",num[i]);
    38         printf("
    ");
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    kubernetes ingress
    kubernetes service
    kubernetes 准入控制器(admission controller)
    kubernetes 自定义指标HPA
    kubernetes horizontal pod autoscaling
    kubernetes cronjob
    kubernetes job
    kubernetes replicationcontroller和replicaset
    kubernetes daemonset
    kubernetes statefulset
  • 原文地址:https://www.cnblogs.com/mis-xiao/p/4043922.html
Copyright © 2011-2022 走看看