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

好容易过了, 求出<m的互质的 大于m的都是在上面加m的倍数

Posted by xiaxia at 2006-03-26 17:44:42 on Problem 2773
In Reply To:超时,请教用什么算法 Posted by:350053879 at 2006-03-26 17:02:15
> #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