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

Why Runtime Error?(C++)

Posted by shiming413 at 2005-10-26 16:37:28 on Problem 2649
//2649_2
#include <stdio.h>
#include <math.h>
bool ss[66000]={0};
int main()
{
	unsigned int i,j,sqrti,m,mm,n,nn;
	for(i=3;i<66000;i++)
	{
		sqrti=int(sqrt(i));
		for(j=2;j<=sqrti;j++)
			if(i%j==0)
			{
				ss[i]=1;
				break;
			}
	}
	bool ans;
	while(scanf("%d%d",&n,&m)==2)
	{
		mm=m;nn=n;
		if(m==0){ans=0;	goto end;}
		for(n=2;n<=nn;n++)
		{
			j=n;
			for(i=2;i<66000&&ss[j];i++)
			{
			    while(j%i==0)
				{
					if(m%i==0)
					    m/=i;
					j/=i;
				}
			}
			if(m%j==0)
				m/=j;
			if(m==1)
				break;
		}
		if(m>1)
			ans=0;
		else
			ans=1;
end:
		if(!ans)
			printf("%d does not divide %d!\n",mm,nn);
		else		
			printf("%d divides %d!\n",mm,nn);
	}
	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