結果

問題 No.1409 Simple Math in yukicoder
ユーザー t33ft33f
提出日時 2021-02-26 23:21:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,397 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 84,160 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-04-10 14:32:24
合計ジャッジ時間 4,788 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,884 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

void check(int v, int x, vector<int>& ans) {
    const int p = v * x + 1;
    for (int i = 1; i < x; i++) {
        long long sum = 0;
        for (int a : ans) sum += modexp(a, i, p);
        cerr << i << ' ' << sum << endl;
        assert(sum % p == 0);
    }
    long long sum = 0;
    for (int a : ans) sum += modexp(a, x, p);
    assert(sum % p == x);
}

int main() {
    int t; cin >> t;
    while (t--) {
        int x, v; cin >> v >> x;
        const int p = x * v + 1;
        for (int g = 2; ; g++) {
            if (modexp(g, (p - 1) / 2, p) != 1) {
                vector<int> ans;
                long long b = modexp(g, v, p), p = 1;
                for (int i = 0; i < x; i++) {
                    ans.push_back(p);
                    p = p * b % (x * v + 1);
                }
                sort(ans.begin(), ans.end());
                for (int i = 0; i < x; i++) {
                    cout << (i == 0 ? "" : " ") << ans[i];
                }
                cout << endl;
                // check(v, x, ans);
                break;
            }
        }
    }
}
0