N!

前言

第一次打压位高精,也不是很难嘛

以前用字符串做高精太蠢了

题目

HDU

Vjudge

正题

暴力就完事了

由于压位,我们第一位不需要补\(0\),直接输出就好了,剩下的要补了\(0\)再输出

怎么补\(0\)呢?

对于剩下的每一位,用\(\%0*lld\)输出,后面传两个参数\(x,y\)

表示输出\(y\),如果不足\(x\)位,用\(0\)补足

代码

//12252024832524
#include <cstdio>
#include <algorithm>
using namespace std; 

typedef long long LL;
const LL MAXN = 4000005;
const LL LEN = 1000000000;
int n;
LL a[MAXN];

int Read()
{
	int x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
void Put1(LL x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
void Put(LL x)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x);
}
template <typename T>T Max(T x,T y){return x > y ? x : y;}
template <typename T>T Min(T x,T y){return x < y ? x : y;}
template <typename T>T Abs(T x){return x < 0 ? -x : x;}

void jc(int x)
{
	int len = 0;
	a[0] = 1;
	for(int i = 2;i <= x;++ i)
	{
		LL jw = 0;
		for(LL j = 0;j <= len;++ j)
		{
			a[j] = a[j] * i + jw;
			jw = a[j] / LEN;
			a[j] %= LEN;
//			printf("%d\n",jw);
		}
		while(jw)
		{
			a[len+1] = jw % LEN;
			jw /= LEN;
			len++;
		}
	}
	printf("%lld",a[len]); a[len] = 0;
	for(int i = len-1;i >= 0;-- i)
	{
		printf("%0*lld",9,a[i]);
		a[i] = 0;
	}
	putchar('\n');
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	while(~scanf("%d",&n))jc(n);
	return 0;
}
posted @ 2020-07-29 09:43  皮皮刘  阅读(993)  评论(0编辑  收藏  举报