結果

問題 No.1409 Simple Math in yukicoder
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2021-02-26 22:59:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,736 bytes
コンパイル時間 1,673 ms
コンパイル使用メモリ 173,704 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 13:42:50
合計ジャッジ時間 25,570 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 6 ms
6,944 KB
testcase_08 AC 16 ms
6,944 KB
testcase_09 AC 6 ms
6,944 KB
testcase_10 AC 14 ms
6,940 KB
testcase_11 AC 16 ms
6,940 KB
testcase_12 AC 13 ms
6,940 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 5 ms
6,944 KB
testcase_15 AC 6 ms
6,940 KB
testcase_16 AC 7 ms
6,944 KB
testcase_17 AC 20 ms
6,940 KB
testcase_18 AC 11 ms
6,944 KB
testcase_19 AC 12 ms
6,940 KB
testcase_20 AC 10 ms
6,948 KB
testcase_21 AC 8 ms
6,944 KB
testcase_22 AC 13 ms
6,944 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 13 ms
6,944 KB
testcase_26 AC 15 ms
6,940 KB
testcase_27 AC 24 ms
6,940 KB
testcase_28 AC 22 ms
6,940 KB
testcase_29 AC 22 ms
6,940 KB
testcase_30 AC 22 ms
6,940 KB
testcase_31 AC 24 ms
6,940 KB
testcase_32 AC 23 ms
6,944 KB
testcase_33 AC 22 ms
6,944 KB
testcase_34 AC 22 ms
6,944 KB
testcase_35 AC 24 ms
6,944 KB
testcase_36 AC 24 ms
6,940 KB
testcase_37 AC 44 ms
6,940 KB
testcase_38 AC 44 ms
6,940 KB
testcase_39 AC 44 ms
6,944 KB
testcase_40 AC 43 ms
6,940 KB
testcase_41 AC 43 ms
6,944 KB
testcase_42 AC 43 ms
6,940 KB
testcase_43 AC 43 ms
6,940 KB
testcase_44 AC 43 ms
6,940 KB
testcase_45 AC 43 ms
6,940 KB
testcase_46 AC 43 ms
6,940 KB
testcase_47 AC 44 ms
6,944 KB
testcase_48 AC 43 ms
6,944 KB
testcase_49 AC 44 ms
6,944 KB
testcase_50 AC 44 ms
6,944 KB
testcase_51 AC 42 ms
6,940 KB
testcase_52 AC 43 ms
6,944 KB
testcase_53 AC 43 ms
6,944 KB
testcase_54 AC 44 ms
6,944 KB
testcase_55 AC 44 ms
6,940 KB
testcase_56 AC 43 ms
6,944 KB
testcase_57 AC 45 ms
6,940 KB
testcase_58 AC 46 ms
6,940 KB
testcase_59 AC 46 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int genshikon(int)':
main.cpp:43:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   43 |         for (auto [q,_] : v) {
      |                   ^

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.02.26 22:53:12
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;



template<typename T>
vector<pair<T,int>> prime_factorization(T n) {
    vector<pair<T, int>> res;
    for (T i = 2; i*i <= n; i++) {
        int cnt = 0;
        while (n % i == 0) {
            n /= i;
            cnt++;
        }
        if (cnt > 0) res.push_back({i,cnt});
    }
    if (n > 1) res.push_back({n,1});
    return res;
}

ll powMod(ll k, ll n, ll mod) {
    ll x = 1;
    while (n > 0) {
        if (n & 1) {
            x = x * k % mod;
        }
        k = k * k % mod;
        n >>= 1;
    }
    return x;
}
int genshikon(int p) {
    auto v = prime_factorization(p-1);
    while(true) {
        int a = rand() % (p-2) + 1;
        for (auto [q,_] : v) {
            
            if (powMod(a,(p-1)/q,p) == 1) {
                a = -1;
                break;
            }
        }
        
        if (a == -1) continue;
        return a;
    }
}
int main() {
    int t;cin >> t;
    while(t--) {
        int v,x;cin >> v >> x;
        if (v == 1 && x == 2) {
            cout << 1 << " " << 2 << endl;
            continue;
        }
        else if (v == 2 && x == 1) {
            cout << 1 << endl;
            continue;
        }
        else if (v == 1 && x == 1) {
            cout << 1 << endl;
            continue;
        }
        int g = genshikon(x*v+1);
        vector<int> ans;
        for (int i = 0; i < x; i++) {
            ans.push_back(powMod(g,i*v,x*v+1));
        }
        sort(ans.begin(), ans.end());
        for (int i = 0; i < x; i++) {
            cout << ans[i] << " ";
        }
        cout << endl;
    }
    return 0;
}
0