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 RUNSLOWLY at 2008-11-03 00:29:09 on Problem 2773
#include<stdio.h>
int main()
{
	int n,i,j,str[1000],m,k,flag=0,num;
	while(scanf("%d%d",&m,&k)!=EOF)
	{
		str[0]=1;
		j=1;
		i=2;
		while(m>=i)
		{
			while(m%i==0)
			{
				m=m/i;
				if(i!=str[j-1])
				{
					str[j++]=i;
				}
			}
			i++;
		}
		n=k;
		k--;
		i=2;
		while(k)
		{
			flag=0;
			for(num=1;num<j;num++)
			{
				if(i%str[num]==0 ||str[num]%i==0)
				{
					flag=1;
					i++;
					break;
				}
			}
			if(flag==0)
			{
				k--;
				i++;
			}
		}
		if(n==1)
			printf("1\n");
		else
    		printf("%d\n",i-1);
	}
	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