方法:打表,排序,比較。
AC代碼:
#include#include #include #include #include #include #include #include #include #include using namespace std; const int maxn = 100000; int list[maxn], radom[maxn]; void Makelist () { int i = 0; for (i = 0; i < maxn; i++) list[i] = i; return ; } int cmp (const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { #ifdef Local freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); #endif int step = 0, mod = 0, i = 0; Makelist(); while (cin >> step >> mod) { int flag = 1; memset(radom, 0, sizeof(radom)); radom[0] = 0; for (i = 1; i <= mod-1; i++) radom[i] = (radom[i-1] + step) % mod; qsort(radom, mod, sizeof(mod), cmp); for (i = 0; i < mod; i++) { if (list[i] != radom[i]) { flag = 0; break; } } if (flag) cout << setw(10) << step << setw(10) << mod << " " << "Good Choice" << endl; else cout << setw(10) << step << setw(10) << mod << " " << "Bad Choice" << endl; cout << endl; } return 0; }