Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
好容易过了, 求出<m的互质的 大于m的都是在上面加m的倍数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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator