依题意可知,只要两个数的最大公约数为1就ok了~
1 #include <stdio.h> 2 int gcd(int a,int b) 3 { 4 int t,min,max; 5 min=a<b?a:b; 6 max=a<b?b:a; 7 while (t=max%min,t!=0) 8 { 9 max=min; 10 min=t; 11 } 12 return min; 13 } 14 int main() 15 { 16 int a,b,g; 17 while (~scanf("%d%d",&a,&b)) 18 { 19 g=gcd(a,b); 20 printf("%10d%10d ",a,b); 21 if(g>1) 22 printf("Bad Choice\n\n"); 23 else 24 printf("Good Choice\n\n"); 25 } 26 return 0; 27 }
本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/archive/2013/03/12/2955332.html,如需转载请自行联系原作者