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 |
超时,请教用什么算法#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