#include "testlib.h" #include #include #include using u64 = unsigned long long int; const int MIN_T = 1; const int MAX_T = 1000; const int MIN_v = 1; const int MAX_v = 1000; const int MIN_x = 1; const int MAX_x = 100; bool is_prime (const int n) { bool res = n > 1; for (int p = 2; p * p <= n; ++p) { res &= n % p != 0; } return res; } u64 pow_mod (u64 r, u64 n, const u64 mod) { u64 t = 1 % mod; while (n > 0) { if (n % 2 == 1) { t = t * r % mod; } r = r * r % mod; n >>= 1; } return t; } u64 primitive_root (const u64 p) { if (p == 2) { return 1; } u64 div[20] = {}; u64 cnt = 0; u64 phi = p - 1; for (u64 i = 2; i * i <= phi; ++i) { if (phi % i == 0) { div[cnt++] = i; while (phi % i == 0) { phi /= i; } } } if (phi > 1) { div[cnt++] = phi; } for (u64 g = 2;; ++g) { bool ok = true; for (u64 i = 0; i < cnt; ++i) { ok &= pow_mod (g, (p - 1) / div[i], p) != 1; } if (ok) { return g; } } } int main(int argc, char** argv) { registerValidation(argc, argv); const int T = inf.readInt(MIN_T, MAX_T, "T"); inf.readEoln(); std::vector v(T); std::vector x(T); for (int i = 0; i < T; ++i) { v[i] = inf.readInt(MIN_v, MAX_v, "v"); inf.readSpace(); x[i] = inf.readInt(MIN_x, MAX_x, "x"); inf.readEoln(); assert(is_prime(v[i] * x[i] + 1)); } inf.readEof(); for (int i = 0; i < T; ++i) { const u64 p = v[i] * x[i] + 1; const u64 g = primitive_root (p); std::vector ans; for (int j = 0; j < x[i]; ++j) { ans.push_back(pow_mod (g, j * v[i], p)); } std::sort(ans.begin(), ans.end()); for (int j = 0; j < x[i]; ++j) { if (j > 0) { std::cout << " "; } std::cout << ans[j]; } std::cout << std::endl; } return 0; }