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 350053879 at 2006-03-26 17:02:15 on Problem 2773
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int gcd(long m,long n)
{
	while(n!=0)
	{
		long temp=m%n;
		m=n;
		n=temp;
	}
    return m;
}
int main()
{
	long m,n;
	long k;
	while(scanf("%ld%ld",&m,&n)!=EOF)
	{
		k=1;
             for(long i=1;;i++)
		{
			 if(gcd(m,i)==1&&k!=n) k++;
			 else if(gcd(m,i)==1&&k==n) 
			 {
				 printf("%ld\n",i);
				 break;
			 } 
		}
	}
	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