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

为什么在zju交不了?

Posted by kef at 2006-04-07 00:56:35 on Problem 2539
#include<stdio.h>
#include<math.h>
int l,i,j,k,t,a,b,s[120],r[120],w[120],x[120];

int main()
{
	while(scanf("%d%d%d",&t,&a,&b)!=EOF)
	{
		if(b==0||t==1)
		{
			printf("(%d^%d-1)/(%d^%d-1) is not an integer with less than 100 digits.\n",t,a,t,b);
			continue;
		}

		if(a==0)
		{
			printf("(%d^%d-1)/(%d^%d-1) 0\n",t,a,t,b);
			continue;
		}

		if(a==b)
		{
			printf("(%d^%d-1)/(%d^%d-1) 1\n",t,a,t,b);
			continue;
		}

		if(a%b!=0||(a-b)*log10(t)>=120)
		{
			printf("(%d^%d-1)/(%d^%d-1) is not an integer with less than 100 digits.\n",t,a,t,b);
			continue;
		}

		k=a/b;

		for(i=0;i<120;i++) w[i]=s[i]=r[i]=0;

		s[0]=1;

		for(i=0;i<b;i++)
		{
			for(l=j=0;j<120;j++)
			{
				s[j]=s[j]*t+l;
				if(s[j]>9)
				{
					l=s[j]/10;
					s[j]%=10;
				}
				else l=0;
			}
		}

		for(i=0;i<120;i++) r[i]=s[i];

		w[0]=1;

		for(l=1;l<k;l++)
		{
			for(j=i=0;i<120;i++)
			{
				w[i]+=s[i]+j;
				if(w[i]>9)
				{
					j=1;
					w[i]-=10;
				}
				else 
					j=0;

				x[i]=0;
			}

			for(i=0;i<120;i++)
				for(j=0;j<120;j++)
					if(i+j<120)
					{
						x[i+j]+=s[i]*r[j];
						if(x[i+j]>9)
						{
							x[i+j+1]+=x[i+j]/10;
							x[i+j]%=10;
						}

					}

			for(i=0;i<120;i++)
				s[i]=x[i];
		}

		i=119;

		while(w[i]==0) i--;

		if(i>99)
		{
			printf("(%d^%d-1)/(%d^%d-1) is not an integer with less than 100 digits.\n",t,a,t,b);
			continue;
		}

		printf("(%d^%d-1)/(%d^%d-1) ",t,a,t,b);
		for(;i>=0;i--) printf("%d",w[i]);

		printf("\n");
	}

	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