本題要確定Step與Mod的最大公因數是否為1,如果不是互質,那麼一定會存在空隙,比如(10,12),其產生為10,8,6,4,2,0,..,空隙為gcd(10,12)=2。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
using namespace std; | |
int gcd(int a, int b) | |
{ | |
while (b){ | |
int temp = a % b; | |
a = b; | |
b = temp; | |
} | |
return a; | |
} | |
int main() | |
{ | |
int step, mod; | |
while (scanf("%d%d",&step,&mod) != EOF){ | |
printf("%10d%10d %s\n\n",step,mod, | |
gcd(step,mod) == 1 ? "Good Choice":"Bad Choice"); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言