1454

/*
大数乘法
*/

// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>

#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>

using namespace std;

// typedef
typedef __int64 LL;

// 
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)

#define Z(a,b) ((a)<<(b))
#define Y(a,b) ((a)>>(b))

const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 1000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);

template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
	if(x>y) return x;
	return y;
}
template<class T> inline T TMIN(T x,T y)
{
	if(x<y) return x;
	return y;
}
template<class T> inline T MMAX(T x,T y,T z)
{
	return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
	return TMIN(TMIN(x,y),z);
}
template<class T> inline void SWAP(T &x,T &y)
{
	T t = x;
	x = y;
	y = t;
}


// code begin
int bignum[200],mod = 10000,top;
int N;
int ans[10];

void dis()
{
	for(int i=top-1;i>=0;i--)
	{
		printf("%04d",bignum[i]);
	}
	printf("\n");
}

int main()
{
	read;
	write;
	int tmp,add;
	while(scanf("%d",&N)!=-1)
	{
		if(!N) break;
		top = 1;
		bignum[0] = 1;

		for(int i=2,j;i<=N;i++)
		{
			// bignum * i;
			add = 0;
			for(j=0;j<top;j++)
			{
				tmp = bignum[j]*i+add;
				add = tmp/mod;
				bignum[j] = tmp%mod;
			}
			while(add)
			{
				bignum[top++] = add%mod;
				add/=mod;
			}
		}
		//dis();

		memset(ans,0,sizeof(ans));
		for(int i=0;i<top-1;i++)
		{
			tmp = bignum[i];
			for(int j=0;j<4;j++)
			{
				ans[tmp%10]++;
				tmp/=10;
			}
		}
		tmp = bignum[top-1];
		while(tmp)
		{
			ans[tmp%10]++;
			tmp/=10;
		}
		printf("%d! --\n",N);
		printf("   (0)%5d    (1)%5d    (2)%5d    (3)%5d    (4)%5d\n",ans[0],ans[1],ans[2],ans[3],ans[4]);
		printf("   (5)%5d    (6)%5d    (7)%5d    (8)%5d    (9)%5d\n",ans[5],ans[6],ans[7],ans[8],ans[9]);
	}
	return 0;
}
posted @ 2011-04-28 20:18  AC2012  阅读(153)  评论(0编辑  收藏  举报