結果
問題 | No.1409 Simple Math in yukicoder |
ユーザー |
![]() |
提出日時 | 2021-02-22 19:52:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 2,150 bytes |
コンパイル時間 | 6,745 ms |
コンパイル使用メモリ | 246,016 KB |
最終ジャッジ日時 | 2025-01-19 03:36:20 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 58 |
ソースコード
#include "testlib.h"#include <vector>#include <iostream>#include <cassert>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<int> v(T);std::vector<int> 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<u64> 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;}