結果

問題 No.1409 Simple Math in yukicoder
ユーザー t33ft33f
提出日時 2021-02-26 23:35:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,876 bytes
コンパイル時間 1,266 ms
コンパイル使用メモリ 84,564 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 14:45:05
合計ジャッジ時間 25,506 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
        if (x == 1) { cout << "1\n"; continue; }
        vector<int> ds;
        int y = x * v;
        for (int i = 2; i * i <= y; i++) {
            if (y % i == 0) {
                ds.push_back(i);
                while (y % i == 0) y /= i;
            }
        }
        if (y > 1) ds.push_back(y);
        for (int g = 2; ; g++) {
            bool ok = true;
            for (int d : ds) {
                if (modexp(g, x * v / d, p) == 1) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                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