zoukankan      html  css  js  c++  java
  • [Uva623]500!(高精)

    Description

    求N!

    (N leq 1000)

    Sample Input

    10

    30

    50

    100

    Sample Output

    10!

    3628800

    30!

    265252859812191058636308480000000

    50!

    30414093201713378043612608166064768844377641568960512000000000000

    100!

    93326215443944152681699238856266700490715968264381621468592963895217599993229915

    608941463976156518286253697920827223758251185210916864000000000000000000000000

    Solution

    简单高精即可

    Code

    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    const int mod=1e5;
    int n,f[1010],len;
    
    int main(){
    	while(~scanf("%d",&n)){
    		f[1]=1;
    		len=1;
    		for(int i=2;i<=n;++i){
    			int pd=0;
    			for(int j=1;j<=len;++j){
    				int tmp=f[j]*i+pd;
    				pd=tmp/mod;
    				f[j]=tmp%mod;
    			}
    			if(pd>0) f[++len]=pd;
    		}
    		printf("%d!
    ",n);
    		printf("%d",f[len]);
    		for(int i=len-1;i;i--)
    			printf("%05d",f[i]);
    		printf("
    ");
    	}
    	return 0; 
    } 
    
  • 相关阅读:
    java中的Class类
    装机
    CSS入门
    初级HTML
    IO加强
    Lambda表达式
    IOStream-基础
    JavaSE阶段基础内容(不包括I/O,常用类,集合)
    markdown学习
    Log4j配置详解
  • 原文地址:https://www.cnblogs.com/void-f/p/7953624.html
Copyright © 2011-2022 走看看