难度:0
涉及算法:GCD
题意:给出一个产生随机数的公式:seed(x+1) = [seed(x) + STEP] % MOD,现在给出STEP和MOD,问能不能产生随机数。
解法:gcd(STEP , MOD) == 1 , 就能。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int gcd(int a , int b) {
if(a == 0) return b;
return gcd(b%a , a);
}
int main() {
int n , m;
while(~scanf("%d%d" , &n , &m)) {
printf("%10d%10d " , n , m);
if(gcd(n , m) == 1) puts("Good Choice");
else puts("Bad Choice");
puts("");
}
return 0;
}