網頁

2014年2月8日 星期六

UVa 408 Uniform Generator

想法:
  本題要確定Step與Mod的最大公因數是否為1,如果不是互質,那麼一定會存在空隙,比如(10,12),其產生為10,8,6,4,2,0,..,空隙為gcd(10,12)=2。


#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;
}

沒有留言:

張貼留言