Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

高精度除法+高精度加法

Posted by Magic347 at 2010-06-24 12:50:58 on Problem 1517
#include<iostream>
#define MAXN 11
using namespace std;
int temp[MAXN][MAXN];
int e[MAXN];
int Fac(int n)
{
	if(n==0||n==1) return 1;
	return n*Fac(n-1);
}
void Div(int d,int r)
{
	int j,n=1;
	for( j=0 ; j<MAXN ; j++ )
	{
		temp[r][j]=n/d;
		if(n%d) n=(n%d)*10;
		else break;
	}
}
void Rnd(int n)
{
	int i,c,t;
	if(n<5) return;
	c=1;
	for( i=MAXN-2 ; i>=0 ; i-- )
	{
		t=e[i]+c;
		e[i]=t%10;
		c=t/10;
	}
}
void Dis_e()
{
	int i,end=-1;
	for( i=MAXN-2 ; i>=0&&end<0 ; i-- )
		if(e[i]) end=i;
	cout<<e[0];
	if(end) cout<<".";
	for( i=1 ; i<=end ; i++ )
		cout<<e[i];
	cout<<endl;
}
void Cal_e(int n)
{
	int i,j,c,t;
	memset(temp,0,sizeof(temp));
	for( i=0 ; i<=n ; i++ )
		Div(Fac(i),i);
	c=0;
	memset(e,0,sizeof(e));
	for( j=MAXN-1 ; j>=0 ; j-- )
	{
		for( i=t=0 ; i<=n ; i++)
			t+=temp[i][j];
		e[j]=(t+c)%10;
		c=(t+c)/10;
	}

	Rnd(e[MAXN-1]);
	Dis_e();
}


int main()
{
	int i;
	cout<<"n e"<<endl;
	cout<<"- -----------"<<endl;
	
	for( i=0 ; i<=9 ; i++)
	{
		cout<<i<<" ";
		Cal_e(i);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator